ipy - Completion For Python Interactive
Bash has awesome command and file completion. I like that. Ruby people are just spoiled with irb.
Python can do that too.
Completion is handled by the rlcompleter
module, aided by the readline
library, and it is all set up with two lines of code.
Example:
Useful, but you want to have that set up automatically (if you can remember or can be bothered to type those liens every time you start python
, you have my deepest respects, yet I’m also slightly suspicious of your sanity). You have two options:
- The
PYTHONSTARTUP
environment variable, which if pointing to the name of a readable filethe Python commands in that file are executed before the first prompt is displayed in interactive mode.
- Running
python -i [script]
, which will cause the interpreter to remain in interactive mode after evaluating the script specified on the command line. You can use it in combination with analias
command.
Start by saving those two lines to a file. I’ll call mine ~/.python_init.py
:
The PYTHONSTARTUP
route sets this environment variable in your personal initialization file, .bashrc
for the bashful of us (why you want bashrc
instead of bash_profile
):
The alias
route defines an alias in your personal initialization file for python -i ~/.python_init.py
:
Now you can start your python interpreter using 50% fewer characters!:
Either works the same, but I would think that PYTHONSTARTUP
, being a set and forget option, would serve you better.
Want to know more? Read the rlcompleter documentation. The readline docs are interesting, too.