我已经看过一些关于此的主题,但似乎并不能解决我的问题。我正在运行linux,当我使用raw_input()时,每个之间都有一个暂停,它将接收我之前按下的数据,这是一个示例:
import time
a = raw_input("first input")
b = raw_input("second input")
time.sleep(5)
#flush junk?
a = raw_input("third input")
b = raw_input("fourth input")
如果我在5秒钟内按任意键,然后按Enter,则另外两个原始输入将采用该输入。我希望能够刷新数据并提示用户。
谢谢。
对于Unix,您可以使用termios.tcflush
from termios import tcflush, TCIFLUSH
import time,sys
a = raw_input("first input ")
b = raw_input("second input ")
time.sleep(5)
tcflush(sys.stdin, TCIFLUSH)
a = raw_input("third input ")
b = raw_input("fourth input ")
~$ python foo.py
first input 1
second input 2
33
33
third input 3
fourth input 4
termios.tcflush(fd,队列)
丢弃文件描述符fd上的排队数据。队列选择器指定哪个队列:输入队列为TCIFLUSH,输出队列为TCOFLUSH,两个队列均为TCIOFLUSH。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句