【问题标题】:How to make an Interactive CLI based application in python?如何在 python 中制作基于交互式 CLI 的应用程序?
【发布时间】:2012-09-19 12:28:04
【问题描述】:

我正在为我们的手持扫描仪编写一个 python 程序。我们必须扫描大量条形码,但我不喜欢一直按“输入”。

您是否可以说:在输入时,如果您输入的字符串正好是 20 个字符,则创建一个新输入?

我可以计算 raw_input() 的返回值,但这并不是我想要的。

【问题讨论】:

标签: python ipython raw-input


【解决方案1】:

你可以使用这个getch函数。

一个小型实用程序类,用于在 Windows 和 UNIX 系统上从标准输入读取单个字符。它提供了一个类似 getch() 函数的实例。

然后您可以简单地使用循环来获取 20 个字符。

import sys
while 1:
    c=''
    while len(c) < 10:
        g = getch()
        sys.stdout.write(g)
        c += g
    print "\nYou said", c

【讨论】:

    猜你喜欢
    • 2013-11-14
    • 1970-01-01
    • 2014-10-30
    • 2017-01-25
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    • 2019-11-21
    • 1970-01-01
    相关资源
    最近更新 更多