Problems with user input
Florian Wilhelm
Florian.Wilhelm at web.de
Tue Nov 9 18:51:57 EST 2004
My OS is Linux 2.6.8.1 and Python version 2.3.4
I just want to write a function that, if called,
asks a yes/no question. The user should only need
to type one char, without confirming with enter.
I wrote a function similar to following
import sys
print "Input: (y/N) ",
input = sys.stdin.read(1)
print "Your input:", input
If I execute these lines and type "y" followed by "enter".
I get this output
Input: (y/N) y
Your input: y
The problem is that there is a whitespace in front of the
second line, that is not generated by the second print
statement. I dont understand why it appears...
It really has nothing to do with the second "print",
because following code:
import sys
print "Input: (y/N) ",
input = sys.stdin.read(1)
print "Hello World"
print "Your input:", input
produces this output...
Input: (y/N) y
Hello World
Your input: y
Can somebody explain why the whitespace char appears
in front of "Hello World"???
More information about the Python-list
mailing list