Windows 下python的tab自动补全

Windows 下python的tab自动补全#

对于新学python的朋友来说,python模块的功能多而难记,mac和Linux中有tab自动补全命令功能,使用Windows的同学们怎么办?下面我们学习一下怎么在windows中用tab自动补全。这里我介绍2种方法:

方法一:安装一个ipython就OK啦,而且关键字还能高亮显示呢##

一、打开cmd,输入pip3 install ipython联网安装###

二、安装成功后,cmd里运行ipython,成功啦。###

方法二:写一个tab代码放到python模块下##

一、新建一个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

二、在cmd中安装readline模块。###

windows中可以输入pip3 install pyreadline联网安装。如图:

三、cmd中import sys, sys.path找到python存放默认模块的路径:###

我这里是:C:\Users\51528\AppData\Local\Programs\Python\Python36\lib\site-packages']

四、将第一步写好的tab.py文件放到默认模块路径下。###

大功要告成啦,

此时再运行cmd>>>import tab>>>import sys >>>sys. 就可自动补全sys模块的所有功能啦。

原文地址:https://www.cnblogs.com/51zf/p/9182791.html