Created
May 4, 2011 12:41
-
-
Save benhodgson/955154 to your computer and use it in GitHub Desktop.
Add history between sessions and auto-completion via the ESC and tab keys to the interactive Python interpreter with this dot-file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python Startup File (from https://gist.github.com/955154) | |
Add this file to ~/.pythonrc.py to add history between sessions and | |
auto-completion via the ESC key to the interactive Python interpreter. After | |
adding this file, put something like the following line in your .bash_profile: | |
export PYTHONSTARTUP=$HOME/.pythonrc.py | |
Requires a recent version of Python and the readline package, which you can | |
install from http://pypi.python.org/pypi/readline or with easy_install. | |
easy_install -U readline | |
""" | |
def _pythonrc(): | |
import atexit | |
import os | |
import readline | |
import rlcompleter | |
readline.parse_and_bind("tab: complete") | |
history = os.path.expanduser("~/.py_history") | |
readline.set_history_length(500) | |
if os.path.exists(history): | |
readline.read_history_file(history) | |
@atexit.register | |
def write_history(history=history): | |
readline.write_history_file(history) | |
_pythonrc() | |
del _pythonrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool pythonrc file. Thank you.