4 ms·
As someone who's never used ipython before, but used the standard python interactive terminal a lot, I'm very impressed! The best feature I've discovered so fa
by thomasahle 10y ago
As someone who's never used ipython before, but used the standard python interactive terminal a lot, I'm very impressed!
The best feature I've discovered so far, is that when I want to change a function, I can simply 'up arrow', and I get the whole thing! Not a single line of the function, as in the normal python terminal. And if I write a syntax error while typing the function, it tells me immediately!
Does anybody have other examples of great features in ipython over the standard python terminal?
- stygiansonic 10y agoTab to autocomplete is pretty sweet.
- brbsix 10y agoYou can still get tab to complete with the standard Python interpreter. python3 -ic "import readline; import rlcompleter; readline.parse_and_bind('tab: complete')" Admittedly, IPython's is better.
- brbsix 10y agoFor one, you can just paste in a bunch of code. Try doing that in the standard terminal! Another feature I end up using constantly is the documentation support. Say you want to read the docstring for an object, just prefix or append a '?' to the object, e.g. 'subprocess?'. If you want to examine the source code for the object, just prefix or append '??', e.g. 'subprocess.call??'.
- thomasahle 10y ago> For one, you can just paste in a bunch of code. Try doing that in the standard terminal! Usually I can paste code just fine, I think? As long as the indentation is correct and I have double blank lines between functions, etc. > Say you want to read the docstring for an object, just prefix or append a '?' to the object, e.g. 'subprocess?' Isn't that the same as typing `help(subprocess)` in the standard terminal? > If you want to examine the source code for the object, just prefix or append '??', e.g. 'subprocess.call??'. That's pretty cool :-)
- brbsix 10y agoJust try pasting the following into the default interpreter, exactly as-is: class Sample: def __init__(self): print('hehe') s = Sample() IPython wouldn't flinch.
- gknoy 10y agoNote that if you're doing this in a terminal, you MIGHT need to first do `%cpaste`: https://gist.github.com/gknoy/97de793db43ff7ea4d4bfd1bab96b408 https://gist.github.com/gknoy/97de793db43ff7ea4d4bfd1bab96b4... It seemed to work fine when I didn't use `%cpaste`, though, so that might be a vestigial thing? (I remember having to do it on my linux workstation, so maybe it's just my mac terminal behaving differently.) The cool thing about directly pasting is, if you fumble the indentation like I did when I initially pasted, it auto-indents for you. ;)
- takluyver 10y agoIn previous releases, you had to use %cpaste. With IPython 5, so long as your terminal supports 'bracketed paste', it should just work. We'll probably deprecate %cpaste eventually. We got this feature with no effort on our part - it's built into prompt_toolkit.
- anentropic 10y ago%debug after an exception :)
- a3n 10y agoWhenever I'm helping someone new to Python, I show them the standard python shell (which itself is often a revelation). Then I show them ipython, and suggest they never go back to the standard shell.
- sixhobbits 10y agofile_list = !ls So much nicer than messing around with subprocess and pipes.
- thomasahle 10y agoWait, what is the syntax for this? I can't do `len(!ls)`?
- carreau 10y agoNo, `!command` only work on assignment. Please read http://ipython.readthedocs.io/en/stable/interactive/tutorial.html http://ipython.readthedocs.io/en/stable/interactive/tutorial... See tutos like https://www.youtube.com/watch?v=xe_ATRmw0KM https://www.youtube.com/watch?v=xe_ATRmw0KM , most of what works in the notebook work in IPython. But yes you can do things like: files = ! ls *.txt for name in files: with open(name) as f: if 'Content-Type: text/x-rst' in f.read(): !git mv {name} {name[:-3]}rst
- deleted 10y ago[deleted]
- ced 10y agoCtrl-R for command history search. Similarly if you type a few characters and do up-arrow, it'll look up commands that start with the same characters. ipython saves every result, you can get it by typing Out[1] (... and it'll take up memory, so beware). Call it with --autocall 2 and then you can omit parentheses in function calls.
- p4wnc6 10y agoThe ability to customize the IPython launch sequence and configure things is something I make heavy use of. For example, here is my IPython launch script [0]. I started out adding to the launch script so that I would have data and helper functions ever-present in my terminal when I was working to rapidly answer Stack Overflow questions, especially for often repeated tropes like group-by in pandas or some broadcasting issues in numpy. But then I started accumulating other things, like the boilerplate for reflecting some local toy databases using SQLAlchemy, and some toy stuff with metaclasses and decorators, and kept going from there. You should read the docs on IPython configuration -- you can even create different profiles and then launch IPython with a specific profile if you want to get different defaults in your launch environment for different use cases [1]. [0] < https://github.com/spearsem/configs/blob/master/ipython_configs/profile_default/launch.py https://github.com/spearsem/configs/blob/master/ipython_conf... > [1] < http://ipython.readthedocs.io/en/stable/config/intro.html http://ipython.readthedocs.io/en/stable/config/intro.html >
- gknoy 10y agoWow. That's pretty cool! I had wrapped ipython in a helper that would always have the Right PYTHON_PATH, but it's neat to see just how much of ipython I have not been using. Thank you for sharing that.
- wodenokoto 10y agoadding a `?` at the end of a function name or other objects brings up the documentation. Extremely handy.