-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.pythonrc
More file actions
57 lines (39 loc) · 1.29 KB
/
.pythonrc
File metadata and controls
57 lines (39 loc) · 1.29 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
54
55
56
"""
Copied from https://gableroux.com/posts/2016-01-20-python-interpreter-autocomplete/
"""
import atexit
import os
try:
import readline
except ImportError:
print(".pythonrc :: Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
print(".pythonrc :: AutoCompletion Loaded")
history_file = os.path.join(os.path.expanduser("~"), ".pyhistory")
print(".pythonrc :: history file:", history_file)
def save_history(history=history_file):
import readline
readline.write_history_file(history)
print(".pythonrc :: history saved to " + history)
def load_history(history=history_file):
try:
readline.read_history_file(history)
except IOError:
pass
load_history()
atexit.register(save_history)
del readline, rlcompleter, atexit, history_file
# In addition to os, import some useful things
# noinspection PyUnresolvedReferences
import re
# noinspection PyUnresolvedReferences
from collections import *
# noinspection PyUnresolvedReferences
from itertools import *
# noinspection PyUnresolvedReferences
from math import *
from datetime import datetime, timedelta as td, timedelta
def date(datestr: str):
return datetime.strptime(datestr, '%Y-%m-%d');