苹果电脑python怎么tabal补全
发布网友
发布时间:2022-04-18 17:42
我来回答
共2个回答
懂视网
时间:2022-04-18 22:04
这篇文章主要为大家详细介绍了你必须了解的python支持tab键补全命令,感兴趣的小伙伴们可以参考一下
cat tab
#!/usr/bin/python
import sys
import readline
import rlcompleter
import atexit
import os
readline.parse_and_bind('tab:complete')
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
热心网友
时间:2022-04-18 19:12
root# cat tab.py
import readline,rlcompleter
### Indenting
class TabCompleter(rlcompleter.Completer):
"""Completer that supports indenting"""
def complete(self, text, state):
if not text:
return (' ', None)[state]
else:
return rlcompleter.Completer.complete(self, text, state)
readline.set_completer(TabCompleter().complete)
### Add autocompletion
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind -e")
readline.parse_and_bind("bind '\t' rl_complete")
else:
readline.parse_and_bind("tab: complete")
### Add history
import os
histfile = os.path.join(os.environ["HOME"], ".pyhist")
try:
readline.read_history_file(histfile)
except IOError:
pass
import atexit
atexit.register(readline.write_history_file, histfile)
del histfile