【发布时间】:2013-05-10 15:13:00
【问题描述】:
我正在尝试编写一个函数来在用户按下选项卡按钮时显示自定义视图。显然“set_completion_display_matches_hook”函数是我需要的,我可以显示自定义视图,但问题是我必须按Enter才能再次获得提示。
Python2 中的解决方案似乎是(solution here):
def match_display_hook(self, substitution, matches, longest_match_length):
print ''
for match in matches:
print match
print self.prompt.rstrip(),
print readline.get_line_buffer(),
readline.redisplay()
但它不适用于 Python3。我做了这些语法更改:
def match_display_hook(self, substitution, matches, longest_match_length):
print('\n----------------------------------------------\n')
for match in matches:
print(match)
print(self.prompt.rstrip() + readline.get_line_buffer())
readline.redisplay()
有什么想法吗?
【问题讨论】:
标签: python python-3.x readline