-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pythonrc
More file actions
36 lines (31 loc) · 1.02 KB
/
.pythonrc
File metadata and controls
36 lines (31 loc) · 1.02 KB
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
# Add auto-completion and make command history available to the interpreter
# Source: http://erbfarm.com/wam/2009/01/24/a-better-pythonrc/
try:
import readline
except ImportError:
pass
else:
import rlcompleter
import os.path
import atexit
class irlcompleter(rlcompleter.Completer):
def complete(self, text, state):
if text == "":
readline.insert_text('\t')
return None
else:
return rlcompleter.Completer.complete(self,text,state)
readline.parse_and_bind("tab: complete")
readline.set_completer(irlcompleter().complete)
# Restore our command-line history, and save it when Python exits.
history_file = os.path.expanduser("~/.pyhistory")
if os.path.exists(history_file):
readline.read_history_file(history_file)
def save_hist():
import readline
readline.write_history_file(history_file)
atexit.register(save_hist)
# Clean up the namespace.
del readline
del os
del atexit