-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpythonrc.symlink
54 lines (42 loc) · 1.33 KB
/
pythonrc.symlink
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
54
# vim:filetype=python
print("Running pythonrc")
import datetime
try:
get_ipython().confirm_exit = False
except:
print('Not running in ipython')
try:
pytz = __import__('pytz')
except ImportError:
print("Can't find pytz - run: pip install pytz")
try:
dateutil = __import__('dateutil')
except ImportError:
print("Can't find dateutil - run: pip install python-dateutil")
else:
from dateutil.relativedelta import relativedelta
import atexit
import os
import readline
import rlcompleter
import readline
import rlcompleter
readline.parse_and_bind('tab: complete')
# Don't trust expanduser with just ~ - it defaults to the pre-sudo username
user = os.environ['USER']
historyPath = os.path.expanduser('~{}/.pyhistory'.format(user))
def save_history(historyPath=historyPath):
import readline
readline.write_history_file(historyPath)
if os.path.exists(historyPath):
readline.read_history_file(historyPath)
atexit.register(save_history)
import csv
def save_csv(filename, data):
with open(filename, 'w', newline='') as csvfile:
writer = csv.DictWriter(csvfile, [type(list(data.keys())[0]), 'value'])
for key, value in sorted(data.items()):
writer.writerow({type(key): key, 'value': value})
import logging
log = logging.getLogger(__name__)
del os, atexit, readline, rlcompleter, save_history, historyPath