How to flush the input stream in python?
Posted
by jinxed_coder
on Stack Overflow
See other posts from Stack Overflow
or by jinxed_coder
Published on 2010-03-26T02:49:53Z
Indexed on
2010/03/26
2:53 UTC
Read the original article
Hit count: 321
python
I'm writing a simple alarm utility in Python.
#!/usr/bin/python
import time
import subprocess
import sys
alarm1 = int(raw_input("How many minutes (alarm1)? "))
while (1):
time.sleep(60*alarm1)
print "Alarm1"
sys.stdout.flush();
doit = raw_input("Continue (Y/N)?[Y]: ")
print "Input",doit
if doit == 'N' or doit=='n':
print "Exiting....."
break
I want to flush or discard all the key strokes that were entered while the script was sleeping and only accept the key strokes after the raw_input() is executed.
© Stack Overflow or respective owner