首页 » 编程 » Python基础 » 正文

python命令行在windows下实现tab自动补全功能

一、安装 pyreadline 模块

模块地址: https://pypi.org/project/pyreadline/

安装方法:打开 cmd ,输入 pip install pyreadline

C:\>pip install pyreadline
Collecting pyreadline
  Downloading https://files.pythonhosted.org/packages/bc/7c/d724ef1ec3ab2125f38a1d53285745445ec4a8f19b9bb0761b4064316679/pyreadline-2.1.zip (109kB)
    100% |████████████████████████████████| 112kB 162kB/s
Installing collected packages: pyreadline
  Running setup.py install for pyreadline ... done
Successfully installed pyreadline-2.1

 

二、新建文件 tab.py ,内容如下:

# python startup file  
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

将文件拷贝到 C:\Python36\Lib\site-packages 目录下。

 

三、验证

在cmd中进入python解释器,随便导入一个模块,使用tab就可以看到其所有的方法。

 

发表评论

*