Thursday, January 12, 2012

Python autocompletion (from the net)

Original source from HERE

Enabling auto-complete in the interactive python interpreter will greatly increase your development speed. Sometimes you can't recall a method's name or you're not sure which method to use in the first place.
First we're going to create a file in your home directory called ".pythonrc" which will hold our configuration details. This file should contain the following:
import rlcompleterreadline
Then we'll set the PYTHONSTARTUP environment variable in our .bashrc (or .bash_profile if you're using that). If the PYTHONSTARTUP variable is set to a readable file, then the contents of that file will be run before anything else when the interactive interpreter is run.
echo "export PYTHONSTARTUP=~/.pythonrc" >> .bashrc
Then either open a new terminal window or reload your .bashrc file:
source ~/.bashrc
You're all set, just run python to enter the interpreter and give it a whirl. For example, run:
import sys
Then type in "sys." and hit tab twice, and you'll see all the methods on the sys object.

No comments:

Post a Comment