Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
snippets for export PYTHONSTARTUP=~/.pythonrc
# This is the actual file that combines all of the other snippets
# I've been using it for a while, so it's officially Bug Free (TM)
# Python startup script. vim: set ft=python :
# from http://www.norvig.com/python-iaq.html
# also see Tarek Ziade's _Expert_Pythom_Programming_ page 19
import os, sys
# Coloured prompt
if os.getenv('TERM') in ('xterm', 'vt100', 'rxvt', 'Eterm', 'putty'):
try:
import readline
except ImportError:
sys.ps1 = '\033[0;32m>>> \033[0m'
sys.ps2 = '\033[0;32m... \033[0m'
else:
sys.ps1 = '\001\033[0;32m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[0;32m\002... \001\033[0m\002'
# Completion!
try:
import readline
except ImportError:
print("Module readline not available.")
else:
# persistent history
histfile = os.path.expanduser('~/.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del histfile, atexit
# tab completion
try:
sys.path.append(os.path.join(os.getenv('HOME'), 'src', 'rlcompleter2'))
import rlcompleter2
rlcompleter2.setup()
del rlcompleter2
except ImportError:
import rlcompleter
readline.parse_and_bind("tab: complete")
del rlcompleter
del readline
del sys
del os
# Coloured prompt
import os, sys
if os.getenv('TERM') in ('xterm', 'vt100', 'rxvt', 'Eterm', 'putty'):
try:
import readline
except ImportError:
sys.ps1 = '\033[0;32m>>> \033[0m'
sys.ps2 = '\033[0;32m... \033[0m'
else:
sys.ps1 = '\001\033[0;32m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[0;32m\002... \001\033[0m\002'
del readline
del os, sys
# Persistent history
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import os
histfile = os.path.expanduser('~/.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del histfile, atexit, readline, os
# Tab-completion
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import os, sys
try:
# look for rlcompleter2 in ~/src, it's a bit more advanced
sys.path.append(os.path.expanduser('~/src/rlcompleter2'))
import rlcompleter2
rlcompleter2.setup()
del rlcompleter2
except ImportError:
# fall back to rlcompleter from the standard library
import rlcompleter
readline.parse_and_bind("tab: complete")
del rlcompleter
del readline, os, sys
@mgedmin

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment