]> code.delx.au - dotfiles/blob - .pythonrc.py
xmonad: change restart key
[dotfiles] / .pythonrc.py
1 #!/usr/bin/env python
2
3 # Useful things to have
4 from __future__ import division
5 from math import *
6 import math
7 import os
8 import re
9 import sys
10
11 import array
12 import cgi
13 from datetime import datetime, timedelta
14 import hashlib
15 import json
16 import random
17 import re
18 import socket
19 import struct
20 import subprocess
21 import tempfile
22 import time
23 import traceback
24 import urllib
25
26 # Not available in Python3
27 try:
28 import StringIO
29 import urllib2
30 import urlparse
31 except ImportError:
32 pass
33
34 # Readline completion of everything :)
35 import rlcompleter, readline, atexit
36 default_completer = rlcompleter.Completer()
37
38 history_path = os.path.expanduser("~/.python_history")
39
40 def my_completer(text, state):
41 if text.strip() == "":
42 if state == 0:
43 return text + "\t"
44 else:
45 return None
46 else:
47 return default_completer.complete(text, state)
48
49 def save_history(history_path=history_path):
50 import readline
51 readline.write_history_file(history_path)
52
53 readline.set_completer(my_completer)
54 readline.parse_and_bind("tab: complete")
55
56 if os.path.exists(history_path):
57 readline.read_history_file(history_path)
58
59 atexit.register(save_history)
60
61 del rlcompleter, readline, atexit
62