Of console I/O, characters, strings & dogs

John Machin sjmachin at lexicon.net
Mon Dec 29 23:52:25 EST 2008


On Dec 30, 11:53 am, David Lemper wrote:
> I am trying getch() from msvcrt.

Unfortunately the msvcrt docs have not been 2to3ified:
"""
msvcrt.getch()
Read a keypress and return the resulting character. Nothing is echoed
to the console. This call will block if a keypress is not already
available, but will not wait for Enter to be pressed. If the pressed
key was a special function key, this will return '\000' or '\xe0'; the
next call will return the keycode. The Control-C keypress cannot be
read with this function.

msvcrt.getwch()
Wide char variant of getch(), returning a Unicode value.
"""
In Python 3.0, getch() returns a length-1 bytes object. getwch()
returns a length-1 str object.
Suggestions:
(1) Do more of the 3.0 tutorial so that you understand the bytes/str
thing.
(2) Use getwch instead of getch
(3) Consider whether the builtins print() and input() cover your needs
for console IO.

HTH,
John



More information about the Python-list mailing list