键盘命令和input()

时间:2019-05-23 00:38:57

标签: python

我正在编写使用键输入来控制事物的代码。在代码的后面,有一个对input(“ prompt”)的调用。单独地,这些工作正常。但是,如果用户已经在input(“ prompt”)行之前按下了按键,则这些击键会出现在他们对input()的答复中。如何避免这种情况?通过清除过去的用户输入而不清除我自己的打印语句,或者将击键用作实际上未在终端中键入的命令。

Motors are locked to let you use your mouse freely. Hit space bar to unlock
Motors are locked to let you use your mouse freely. Hit space bar to unlock
Please enter the 3 times in seconds of ccd camera video, separated by a space:       1 2 3
Traceback (most recent call last):
  File "Code for motor motion.py", line 71, in <module>
    timeList.append(int(e))
ValueError: invalid literal for int() with base 10: ''

因此,开始是使用空格键切换安全功能。然后,用户需要输入时间数据,但是数字前面带有一串空格。我知道如何从一开始就删除空格,但是我希望它在一般情况下也可以使用,还有其他命令。

谢谢!

0 个答案:

没有答案