3 回答

TA贡献1824条经验 获得超5个赞
首先,Python 2代码使用逗号使行未完成。在Python 3中,使用end关键字完成:
print(self.prompt.rstrip(), readline.get_line_buffer(), sep='', end='')
然后,需要刷新才能显示未完成的行(由于行缓冲):
sys.stdout.flush()
redisplay()似乎不需要该呼叫。
最终代码:
def match_display_hook(self, substitution, matches, longest_match_length):
print()
for match in matches:
print(match)
print(self.prompt.rstrip(), readline.get_line_buffer(), sep='', end='')
sys.stdout.flush()

TA贡献1805条经验 获得超9个赞
这个为我工作,用于重新显示替换,并且显示python3的比赛结束:
def match_display_hook(self, substitution, matches, longest_match_length):
print("")
for match in matches:
print(match)
print("")
sys.stdout.write(substitution)
sys.stdout.flush()
return None
而以前使用打印提示的用户则没有。(没有找到问题的根源)
添加回答
举报