windows Windows中的python选项卡完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1081405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:45:56  来源:igfitidea点击:

python tab completion in windows

pythonwindowsreadlinetab-completion

提问by Nate

I'm writing a cross-platform shell like program in python and I'd like to add custom tab-completion actions. On Unix systems I can use the built-in readline module and use code like the following to specify a list of possible completions when I hit the TAB key:

我正在用 python 编写一个像程序一样的跨平台 shell,我想添加自定义选项卡完成操作。在 Unix 系统上,我可以使用内置的 readline 模块并使用如下代码来指定当我按下 TAB 键时可能的补全列表:

import readline
readline.parse_and_bind( 'tab: complete' )
readline.set_completer( ... )

How can I do this on Windows? I'd like to avoid relying on 3rd-party packages if possible. If no solution exists is it possible to simply trap TAB key press so that I can implement my own from scratch?

如何在 Windows 上执行此操作?如果可能,我想避免依赖第 3 方软件包。如果不存在解决方案,是否可以简单地捕获 TAB 按键,以便我可以从头开始实现自己的解决方案?

回答by sunqiang

Do u have a look at PyReadline: a ctypes-based readline for Windows? Although 3rd-party packages is NOT your option, maybe it's useful for build one's own, isn't it:).

你看看PyReadline: a ctypes-based readline for Windows吗?虽然 3rd-party 软件包不是您的选择,但也许它对构建自己的软件包很有用,不是吗:)。

回答by David Cournapeau

you could look at how ipythondoes it with pyreadline as well, maybe

你也可以看看ipython如何用pyreadline做到这一点,也许

回答by system PAUSE

Another possibility to check out is readline.py.

另一种检查的可能性是readline.py