欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python的自动tab补全模块

程序员文章站 2024-01-01 11:04:22
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

上一篇:

下一篇: