Useful in case you don't want to install iPython.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #!/usr/bin/env python
"""
Python interpreter auto-completion, history and colored tracebacks.
Installation:
$ wget http://code.activestate.com/recipes/578098/download/1/ -O ~/.pythonstart
$ echo "export PYTHONSTARTUP=~/.pythonstart" >> ~/.bashrc
$ source ~/.bashrc
"""
# Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
# License: MIT
if not hasattr(__name__, "__file__"): # interpreter mode
def autocomplete():
import atexit
import os
import readline
import rlcompleter
def save_history():
readline.set_history_length(10000)
readline.write_history_file(history_path)
history_path = os.path.expanduser("~/.pyhistory")
if os.path.exists(history_path):
readline.read_history_file(history_path)
atexit.register(save_history)
readline.parse_and_bind('tab: complete')
autocomplete()
del autocomplete
|
Quick install:
- wget http://code.activestate.com/recipes/578098/download/1/ -O ~/.pythonstart
- echo "export PYTHONSTARTUP=~/.pythonstart" >> ~/.bashrc
- source ~/.bashrc
One liner:
- wget http://code.activestate.com/recipes/578098/download/1/ -O ~/.pythonstart && echo "export PYTHONSTARTUP=~/.pythonstart" >> ~/.bashrc && source ~/.bashrc
UP and DOWN arrow keys can be used to walk through the history.
- Auto completion is enabled by pressing TAB and looks like this:
>>> axis = 5
>>> a
abs( all( and any( apply( as assert axis