Problems with user input

F. Petitjean littlejohn.75 at noos.fr
Tue Nov 9 18:31:40 EST 2004


On Tue, 09 Nov 2004 23:54:37 Florian Wilhelm <Florian.Wilhelm at web.de> wrote:
> 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?!?
sys.stdin is : buffered and line oriented.
What is your operating system ? Under unix sys.stdin (and C stdin
stream) are managed by a driver which expect you can somewhat modify
the line you want to send to the system. (POSIX normalized)
  If you want a fine control, you can use curses (Unix) or build your
  solution based on getchar (or is it getch() ?) on windows/dos.
> 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?
Tell us more about what you want to do.
> 
> Regards,
> Florian
> 



More information about the Python-list mailing list