当前位置: 移动技术网 > IT编程>脚本编程>Python > python的自动tab补全模块

python的自动tab补全模块

2020年08月10日  | 移动技术网IT编程  | 我要评论
Windows 下python的tab自动补全写一个tab代码放到python模块下一、新建一个tab.py文件。# python startup fileimport sysimport readlineimport rlcompleterimport atexitimport os# tab completionreadline.parse_and_bind('tab: complete')# history filehistfile = os.path.join(os

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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网