1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 1#!/usr/bin/env python
2# python startup file
3import sys
4import readline
5import rlcompleter
6import atexit
7import os
8import platform
9# tab completion
10readline.parse_and_bind('tab: complete')
11# history file
12histfile = os.path.join(os.environ['HOME' if platform.system() == "Linux" else "HOMEPATH"] , '.pythonhistory')
13try:
14 readline.read_history_file(histfile)
15except IOError:
16 pass
17atexit.register(readline.write_history_file, histfile)
18del os, histfile, readline, rlcompleter
19
备注:readline需要在linux环境下安装,window下需要安装pyreadline来替代。
文件保存为tab.py(或者其他文件名),放到目录C:\Python27\Lib\site-packages下即可(linux一样)。进入python环境,直接import tab(文件名),既可实现自动补全提示。