getch() of Turbo C in Python?

D-Man dsh8290 at rit.edu
Thu Jun 7 15:30:24 EDT 2001


On Thu, Jun 07, 2001 at 12:08:35PM -0700, Anurag Ved wrote:
| Hi all,
|   I am using the Python interpreter under Windows. When I execute a
| Python script, the console window that opens up closes immediately
| after the program terminates, leaving me no time to observe the
| output. One solution is to append the program with
| 
| raw_input('')
| 
| But, this is certainly not elegent and moreover it requires the user
| to press 'enter' rather than the preferred option of 'any key'.
| 
| Is there something similar to the getch() function of Turbo C which
| reads just one key from <stdin> and returns immediately?

It's always possible to wrap the desired C function using the
extending API.  The alternative is to fix WIndows.  This default
behavior of not letting one see the error message is a royal pain.
You can either open a shell window, then run your program from it
(this is what I do because I use bash extensively) or configure the
shortcut that launches Python to not close the DOS box automatically.

-D





More information about the Python-list mailing list