CLEAR INPUT BUFFER


S

Sam

Good day!

I have a problem with Python and the input buffer.
My application must read a barcode from PS2 and then
process it.
The problem is: i have to discard all
characters inserted in buffer while Elaborate(data)
is running.
I tried to clear the buffer using sys.stdin.flush() but
it seem not work.

proc Principale() :
while True
# sys.stdin.flush()
data = sys.stdin.readline()
Elaborate(data)


proc Elaborate() :
sleep(5)


I'll apreciate any help!
Thanks
 
Ad

Advertisements

I

Istvan Albert

Sam said:
I tried to clear the buffer using sys.stdin.flush() but
it seem not work.

In general you can't flush the standard input,
it is one of those undefined behaviors in C.

To read the input until an end-of-file is reached
use read() instead of readline().

Istvan.
 
Ad

Advertisements

S

Sam

Istvan Albert said:
In general you can't flush the standard input,
it is one of those undefined behaviors in C.

To read the input until an end-of-file is reached
use read() instead of readline().

Now I try.
Thanks.

Bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top