Reading an exact number of characters from input

Paddy O'Loughlin patrick.oloughlin at gmail.com
Thu Apr 16 11:40:27 EDT 2009


Hi,
How would I use python to simply read a specific number of characters
from standard input?

raw_input() only returns when the user inputs a new line (or some
other special character).
I tried
>>> import sys
>>> sys.stdin.read(15)

and that *returns* up to 15 characters, but it keeps accepting input
(and doesn't return) until I press Enter.

My initial thoughts are that a function like C's fgetc would be the
easiest way to do it, but I haven't been able to find an equivalent in
my google search, so I was wondering if anyone here might have some
ideas.

What say you?

Paddy

-- 
"Ray, when someone asks you if you're a god, you say YES!"



More information about the Python-list mailing list