首页 > IT职业 > IT职场 > Python 自动补全模块
for linux
#!/usr/bin/env python # python startup file import sysimport readlineimport rlcompleterimport atexitimport 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: passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter
把上面代码保存为tab.py放置在当前系统全局环境变量下,可以使用print(sys.path)查看,如:/usr/lib64/python2.6/site-packages
for mac
import sysimport readlineimport rlcompleterif 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 macfor mac
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2611/viewspace-2804790/ ,如需转载,请注明出处,否则将追究法律责任。