-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpythonstartup.py
40 lines (30 loc) · 882 Bytes
/
pythonstartup.py
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
"""
Improve the Python REPL.
Inspired by this tweet by @nedbat:
https://twitter.com/nedbat/status/817827164443840512
Features:
* Use pprint() by default.
https://gist.github.com/chekunkov/848c3472d4b0bee69bccd2e77907a590
* Tab completion
https://github.com/patrik-johansson/dotfiles/blob/master/.pythonstartup
"""
import pprint
import readline
import sys
def displayhook_pprint(o):
"""Display hook powered by pprint.
https://www.python.org/dev/peps/pep-0217/
"""
if o is None:
return
if sys.version_info[0] == 2:
import __builtin__ as builtins
else:
import builtins
# Set '_' to None to avoid recursion
# https://docs.python.org/3/library/sys.html#sys.displayhook
builtins._ = None
pprint.pprint(o)
builtins._ = o
sys.displayhook = displayhook_pprint
readline.parse_and_bind("tab: complete")