Thursday, April 14, 2011

Autocompletetion in the Python console

Hans tells us how to have autocompletion in the Python console:

"
It is handy to be able to tab-complete properties of python objects at the python prompt. Nowadays, I am always using IPython, a significantly enhanced interactive python console which is really worth the installation. (It helps you with completion, indentation, syntax highlighting, macros, input/output caching, session management, improved history, debugger, and tracebacks. And more. ;-) )
However, I find it interesting to note that it is possible to have completion in the standard python console (if compiled with readline, which it really should be)! The following code can be used to activate it:
# .pythonrc.py
import readline, rlcompleter
readline.parse_and_bind("tab: complete")
Put this code in a file ~/.pythonrc.py or similar, and use the variable PYTHONSTARTUP to point python to it! (I.e., I put "export PYTHONSTARTUP=$HOME/.pythonrc.py" into my shell environment setup.)
Now, go check out IPython. ;-)
"

http://kogs-www.informatik.uni-hamburg.de/~meine/python_tricks

No comments: