forked from acornejo/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pythonrc
52 lines (42 loc) · 1.46 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Save as ~/.pythonrc and add 'export PYTHONSTARTUP=~/.pythonrc' to ~/.bashrc
# from http://www.digitalprognosis.com/opensource/scripts/pythonrc
try:
import readline
except ImportError:
pass
else:
import os
import atexit
import rlcompleter
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)
# You could change this line to bind another key instead tab.
readline.parse_and_bind("tab: complete")
readline.set_completer(irlcompleter().complete)
# Restore our command-line history, and save it when Python exits.
historyPath = os.path.expanduser("~/.python_history")
# Create a blank history file if it doesn't exist already
if not os.path.exists(historyPath) and not os.path.isdir(historyPath):
try:
open(historyPath, 'w').close()
# Gracefully ignore things if historyPath is not writable
except IOError:
pass
# Read the history file in for autocompletion and save it on exit
if os.access(historyPath, os.W_OK):
atexit.register(lambda x=historyPath: readline.write_history_file(x))
if os.access(historyPath, os.R_OK):
try:
readline.read_history_file(historyPath)
except:
pass
from pprint import pprint as pp
from pprint import pformat as pf
def t(*args):
return timeit.Timer(*args).timeit()
# vim: ft=python