Windows环境下Python2(或2.7版本)命令行tab自动补全设置

Windows下Python命令行自动补全设置

    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

转载自 https://blog.csdn.net/cyn1025/article/details/49641257?utm_source=blogxgwz2

发布了43 篇原创文章 · 获赞 95 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/weixin_42139375/article/details/83239360