Windows下Python2.7的命令行自动补全与Linux下的代码稍微有些不同,需要修改一下。
#-*- encoding:utf-8 -*-
# python startup file
#添加python自动补全功能
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOMEPATH'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
1、首先需要在Python\Lib\site-packages\下添加readline模块的:
Readline-1.7-py2.7.egg-info
readline.py
readline.pyc
_rlsetup.pyd
2. 最关键:将代码复制到startup.py中时注意要将os.environ['HOME']改为HOMEPATH,不然还会在命令行中出错。
3. 最后,添加系统环境变量:PYTHONSTARTUP=C:\Python27\startup.py