-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.pythonrc.py
More file actions
30 lines (23 loc) · 732 Bytes
/
.pythonrc.py
File metadata and controls
30 lines (23 loc) · 732 Bytes
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
# startup script for python to enable saving of interpreter history and
# enabling name completion
# import needed modules
import atexit
import os
import readline
import rlcompleter
# where is history saved
historyPath = os.path.expanduser("~/.pyhistory")
# handler for saving history
def save_history(historyPath=historyPath):
import readline
readline.set_history_length(10000)
readline.write_history_file(historyPath)
# read history, if it exists
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
# register saving handler
atexit.register(save_history)
# enable completion
readline.parse_and_bind('tab: complete')
# cleanup
del os, atexit, readline, rlcompleter, save_history, historyPath