reading one byte from stdin

Fredrik Lundh fredrik at pythonware.com
Wed Jul 16 04:57:52 EDT 2008


Mark McDuff wrote:

> I'm trying to read one byte from stdin, without the newline.
> 
> If I try something like:
>  >>> import os, sys
>  >>> os.read(sys.stdin.fileno(),1)
> 
> I can input a character, but then I have to press enter, which leaves a 
> newline character in the stdin buffer and requires two keypresses.  Is 
> there any way to read only one keypress in a simple manner (i.e. no 
> curses)?

in addition to the cookbook article Diez posted, there's also a FAQ 
entry about this:

http://effbot.org/pyfaq/how-do-i-get-a-single-keypress-at-a-time.htm

</F>




More information about the Python-list mailing list