[Pythonmac-SIG] Single character input example:

Jack Jansen jack@oratrix.nl
Thu, 06 Jul 2000 10:38:54 +0200


> I am trying to code a simple "press any key to continue". I thought:
> 	print "press any key to continue"
> 	sys.stderr.read(1)
> would do it, but it doesn't continue until the user types a <return> 
> (no matter how many characters the user types). Am I missing 
> something obvious? Is this a bug in the Mac Python 1.5.2c?

I/O to stdin/stdout/stderr is always line-based in MacPython, so this won't 
work. If you really want to do this you could use Evt.WaitNextEvent() with 
only keyboard events in the mask.

> By the way, what I'm really trying to do is get the interpreter to 
> pause at the end (until the user is satisfied) and then quit without 
> forcing the user to type ctrl-Q.

But what's wrong with
>>> print "Type return to exit-"
>>> sys.stdin.readline()

I don't really see why that is worse than
>>> print "Type any key to exit-"
>>> lots_of_complicated_code
--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++
www.oratrix.nl/~jack    | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm