-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.pythonrc
More file actions
53 lines (40 loc) · 1.57 KB
/
Copy path.pythonrc
File metadata and controls
53 lines (40 loc) · 1.57 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
import atexit, os, readline, sys
if sys.version_info >= (3, 0) and hasattr(sys, 'real_prefix'): # in a VirtualEnv
PYTHON_HISTORY_FILE = os.path.join(os.environ['HOME'], '.python_history')
if os.path.exists(PYTHON_HISTORY_FILE):
readline.read_history_file(PYTHON_HISTORY_FILE)
atexit.register(readline.write_history_file, PYTHON_HISTORY_FILE)
# Get reload function
if sys.version_info >= (3, 0) and sys.version_info <= (3, 3):
from imp import reload
elif sys.version_info >= (3, 4):
from importlib import reload
if os.environ.get("USEFUL_SCRIPTS"):
sys.path.append(os.environ.get("USEFUL_SCRIPTS")+'/python')
#sys.ps1='\x1b[1;49;33m>>>\x1b[0m ' # bright yellow
#sys.ps2='\x1b[1;49;31m...\x1b[0m ' # bright red
if 'get_history' not in globals():
import readline
def get_history(tail=-1):
length = readline.get_current_history_length()
start = length if tail==-1 else length-tail
for i in range(readline.get_current_history_length()):
yield readline.get_history_item(i + 1)
if 'history' not in globals():
def history(tail=-1):
hist = get_history(tail)
for i in hist:
print(i)
if 'save_history' not in globals():
def save_history(filename, tail=-1):
hist = list(get_history(tail))
with open(filename, 'w') as stream:
stream.write("\n".join(hist))
def jp(data, **kwargs):
"""
A simple wrapper for json.dumps
"""
import json
indent = kwargs.pop("indent", 2)
print(json.dumps(data, indent=indent, **kwargs))