,因爲它使用libedit/editline,語法啓用自動完成是有一點點不同。 你可以先通過鍵入強制emacs的綁定(因爲它是如果我沒看錯的ReadLine):
readline.parse_and_bind("bind -e")
然後你就可以自動完成添加鏈接到您的TAB鍵(男editrc):
readline.parse_and_bind("bind '\t' rl_complete")
如果你想支持縮進和有歷史(互聯網上找到),它應該是一個(除非我犯了一個錯誤):
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
你之前完成了什麼樣的東西? –
你有沒有考慮過使用類似ipython或bpython的東西? –
如果它仍然無法正常工作,請參閱[我在另一篇文章中的回答](http://stackoverflow.com/questions/675370/tab-completion-in-python-interpreter-in-os-x-terminal/23908884# 23908884)。 –