Skip to content

Instantly share code, notes, and snippets.

@artyom
Created September 27, 2012 12:58
Show Gist options
  • Save artyom/3793856 to your computer and use it in GitHub Desktop.
Save artyom/3793856 to your computer and use it in GitHub Desktop.
pretty python interpreter (tab-completion, etc.) for Linux & Mac OS X
#!/usr/bin/env python
# save this file as $HOME/.pythonrc.py
# add `export PYTHONSTARTUP=$HOME/.pythonrc.py` to your .bashrc
import os
import atexit
import sys, pprint
import readline, rlcompleter
histfile = os.path.join(os.path.expanduser("~"), ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
# for details read `man readline` on linux, `man editline` on OSX
if sys.platform.startswith('linux'):
readline.parse_and_bind("tab: complete")
elif sys.platform == 'darwin':
readline.parse_and_bind("bind ^I rl_complete")
readline.set_history_length(1000)
atexit.register(readline.write_history_file, histfile)
sys.displayhook = pprint.pprint
del os, histfile, readline, rlcompleter, atexit, sys, pprint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment