]> code.delx.au - dotfiles/blob - .pythonrc.py
Better with IMAP
[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 socket
16 import StringIO
17 import struct
18 import subprocess
19 import time
20 import traceback
21 import urllib
22
23
24
25 # Readline completion of everything :)
26 import rlcompleter, readline, atexit
27 defaultCompleter = rlcompleter.Completer()
28
29 historyPath = os.path.expanduser("~/.pyhistory")
30
31 def myCompleter(text, state):
32 if text.strip() == "":
33 if state == 0:
34 return text + "\t"
35 else:
36 return None
37 else:
38 return defaultCompleter.complete(text, state)
39
40 def save_history(historyPath=historyPath):
41 import readline
42 readline.write_history_file(historyPath)
43
44 readline.set_completer(myCompleter)
45 readline.parse_and_bind("tab: complete")
46
47 if os.path.exists(historyPath):
48 readline.read_history_file(historyPath)
49
50 atexit.register(save_history)
51
52 del rlcompleter, readline, atexit
53