您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何使python命令行程序自动完成任意内容而不是解释程序

如何使python命令行程序自动完成任意内容而不是解释程序

使用Python的readline绑定。例如,

import readline

def completer(text, state):
    options = [i for i in commands if i.startswith(text)]
    if state < len(options):
        return options[state]
    else:
        return None

readline.parse_and_bind("tab: complete")
readline.set_completer(completer)

官方模块文档没有更多详细信息,请参阅readline文档获取更多信息。

python 2022/1/1 18:35:29 有221人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶