5 ms·
Enable tab-completion in the interactive interpreter by default
- Goranek 13y agoI always wondered why default interpreter can't be more like bpython. Good work
- thauck 13y agoSome would argue why it can't be more like IPython. :) But agreed, good work... tab completion is very helpful when learning a language.
- Goranek 13y agoIPython seems to be "too heavy" for me compared to Bpython :) Bpython is perfect for me.
- JasonFruit 13y agoI had the same feeling about IPython, and I rather liked bpython — and then I discovered DreamPie, which offers a number of features I have found useful in exploratory programming. Yes, it moves me out of both Emacs and my terminal, but it's almost worth it.
- gknoy 13y agoThe thing that soured me on bpython, after loving it for months, was the realization that I could not scroll back easily to see results of past things (aside from the most recent one). Ipython (and, even better, the qtconsole for it) does that much better. In a console, I like bpython's interface and autocomplete suggestion interface, but being unable to scroll back and see what I did 3 commands ago was a deal killer.
- tshepang 13y agoThe related Issue has been open since 2009: http://bugs.python.org/issue5845 http://bugs.python.org/issue5845.
- est 13y agoTo use tab completion in earlier Python versions: import readline, rlcompleter; readline.parse_and_bind("tab: complete")
- gsa 13y agoTo make it seamless, put those lines in ~/.pythonrc and add this to your zshrc export PYTHONSTARTUP="$HOME/.pythonrc"
- niggler 13y agoon OSX you need readline.parse_and_bind('bind ^I rl_complete')
- alexpopescu 13y agoI use a combination of all these 3 tricks as I have my dotfiles shared between Mac and Linux. Basically my pythonstartup.py contains the extra check for os: AP_AUTOCOMPLETE=False import sys try: import readline except ImportError: print "Module readline unavailable" else: import rlcompleter readline.parse_and_bind("tab: complete") if sys.platform == 'darwin': readline.parse_and_bind("bind ^I rl_complete") AP_AUTOCOMPLETE=True
- jayflux 13y agoAntoine Pitrou has certainly contributed a lot to CPython. good work
- eliben 13y agoHe most certainly did! But did you notice the commit says "original patch by Éric Araujo" ?
- obviouslygreen 13y agoWow, it's about time. It's not that hard to set up tab completion using a startup script, but that always struck me as sort of a backwards thing to have to do every time I set up a new server or workstation.
- ak217 13y agoTangentially related: Shell tab completion for Python programs using argparse: https://github.com/kislyuk/argcomplete https://github.com/kislyuk/argcomplete
- jfb 13y agoNext up: sqlplus.
- deleted 13y ago[deleted]
- dmd 13y agoThis is great, but is there any reason whatsoever not to use ipython?
- sigzero 13y agoMaybe in a restricted environment where you can't install it?
- tshepang 13y agoI can think of a few: * awareness * the official interpreter works quite well already * yet-another-tool to learn
- a3n 13y ago* You're in an interview and they don't have it.
- aaronharnly 13y agoI use virtualenv for all projects, and frequently destroy and recreate virtualenvs. iPython takes a good while to install; doing it over and over again in fresh virtualenvs gets to be a chore, so I tend to do it only when I really need it. I dunno, is there a better way, maybe installing iPython globally, but rewriting the shebang line to use /usr/bin/env python?
- tshepang 13y agoYou can always install it directly, and not in a virtualenv. Am I missing something?
- xnxn 13y agoThat would require you to enable global site- packages for that virtualenv.
- Buttons840 13y agoIf it's installed globally then it wont have access to the libraries installed only in the virtualenv. I think there's a way to work around this, but I haven't taken the time to look into it.
- oellegaard 13y agoWill this be on 2.7.x or just 3.x?
- tshepang 13y ago3.4, early next year http://www.python.org/dev/peps/pep-0429 http://www.python.org/dev/peps/pep-0429
- circuiter 13y agoIs there anything that would prevent this from being backported to 2.x.x ?
- yuvadam 13y agoYeah, 2.x versions are only updated with security-related patches.
- tshepang 13y agoNot exactly. 2.7 still gets bugfixes.
- mh- 13y agopolitics
- tshepang 13y agoNone of the releases deemed final accept any new features. It's general release policy for any FLOSS project, and only neglected on rare occasions.
- cben 13y agoThere is a recent PEP excluding IDLE from this policy, allowing it to get usability improvements on older pythons. One could think that enabling completions is a similar usability fix (though one change isn't worth the arguing to get exception) but in fact this change required a new var in `sys` and changed site.py, both unacceptable for a minor release. That's even for backport to 3.3. As for 2.7, even when when allowed, most changes aren't backported to it simply because the code has diverged a lot and core devs are tired of implementing changes twice.
- spicavigo 13y agoI don't remember the last time I used anything except iPython. I use EC2 a lot, and the first thing I do after firing an instance is install ipython, even if I don't intend to use the instance for python related stuff at all.
- digisign 13y agoI've always wondered why so many of these usability niceties have been available yet neglected soooo long, while the language as a whole has progressed so much? There are plenty more of these, like interpreter history and adding pip to the stdlib. On Windows it's even worse, newbies have to figure out how to get it in their path and hunt-down important libraries.
- tshepang 13y agoThe mystery goes away once you start reading python-dev and watching bugs.python.org... people find it hard to agree on the right way to do things. It takes a lot of energy for the bigger changes to go in, and many of those with the energy are busy working on other things, while the Issues rot. CPython needs more contributors (as does so many volunteer software projects).
- mixmastamyk 13y agoHmm, they might take a cue from the Active State distribution, who has done a lot of things right.
- mixmastamyk 13y agoBTW, are you implying/do you think I could get some of these in with some enthusiasm and a bit of work (given they've been implemented for a decade).
- tshepang 13y agoYou have a better chance of success if you try. Even respected core developers, including Guido himself, fail to get stuff they want in. So, no, it's no guarantee.
- Camillo 13y agoOne problem with tab completion is that you can no longer paste tab-indented snippets into the intepreter, or use tab to indent code you're typing. I put the following in my python startup file to fix the issue: import readline, rlcompleter readline.parse_and_bind("tab: complete") readline.parse_and_bind('bind ^I rl_complete') class MyCompleter(rlcompleter.Completer): def complete(self, text, state): if text.lstrip() == '': if state == 0: return text + '\t' else: return None else: return rlcompleter.Completer.complete(self, text, state) readline.set_completer(MyCompleter().complete)
- alexpopescu 13y agoNiiiice!