如何使用 Python 写出交互式的命令行程序

2015-04-12 18:07:07 +08:00
 caizixian
就像fdisk之类的一样
有旧帖提到这个问题 /t/99667
不过貌似没有很好的答案。
不知到有没有什么方法/库能够做到这一点(最好支持tab补全)

目前能想到的一种方式就是input('>')然后自己读进来,但是感觉很不优雅,也不支持补全
2884 次点击
所在节点    Python
5 条回复
cbsw
2015-04-12 18:29:38 +08:00
http://pymotw.com/2/cmd/ 里面提到有 tab 补全
swordfeng
2015-04-12 18:39:33 +08:00
curses?
wenLiangcan
2015-04-12 19:29:29 +08:00
Library for building powerful interactive command lines in Python:

https://github.com/jonathanslenders/python-prompt-toolkit
caizixian
2015-04-12 19:36:42 +08:00
wuyu1998
2015-04-15 11:48:11 +08:00

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/183257

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX