Problems with user input

Florian Wilhelm Florian.Wilhelm at web.de
Tue Nov 9 23:54:37 CET 2004


I have some easy questions, but I cant figure them out:

I want to read exactly one char from stdin, there should
be no need to hit enter.

import sys

print "Input: (y/N) ",
input = sys.stdin.read(1)
print "Your input:", input

This code has following problems:
1) I need to hit enter, although I read only one char?!?
2) The complete output is:

Input: (y/N) y
 Your input: y

Why does the whitespace char appear in front of "Your input..."?
I guess it has something to do with not causing a linebreak
after "Input: (y/N) ", but I want no linebreak...

Any suggestions?

Regards,
Florian




More information about the Python-list mailing list