Windows 下python的tab自动补全
写一个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模块的所有功能啦。
mac的自动补全代码
import sys
import readline
import rlcompleter
if sys.platform == 'darwin' and sys.version_info[0] == 2:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete") # linux and python3 on mac
linux补全
#!/usr/bin/env python
# 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['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
——想了解更多的话,可以关注公众号huawangxin。
本文地址:https://blog.csdn.net/huawangxin/article/details/107876393
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论