Reading an exact number of characters from input

P

Paddy O'Loughlin

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
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
 
D

Diez B. Roggisch

Paddy said:
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

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.

Maybe ncurses helps. Or you can use termios and set the terminal into
non-canonical mode which will let you get characters as they appear, not
only after a newline.

Diez
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top