-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpythonrc
36 lines (28 loc) · 1.03 KB
/
pythonrc
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
36
# ~/.pythonrc
# https://gist.github.com/GabLeRoux/8584525
# https://github.com/tony/.dot-config/blob/master/.pythonrc
# enable syntax completion
from __future__ import print_function
import sys
if sys.version_info < (3, 4):
# Activation of rlcompleter and history is automatic since v3.4
# https://docs.python.org/3/library/site.html#readline-configuration
import atexit
import os
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
# History
history_path = os.path.expanduser("~/.python_history")
def save_history(history_path=history_path):
import readline
readline.write_history_file(history_path)
if os.path.exists(history_path):
readline.read_history_file(history_path)
atexit.register(save_history)
# anything not deleted (sys and os) will remain in the interpreter session
del atexit, readline, rlcompleter, save_history, history_path