[Tutor] Looking for suggestions for improving chessTimer.py code

Alan Gauld alan.gauld at btinternet.com
Sat Oct 27 10:13:45 CEST 2007


"Dick Moores" <rdm at rcblue.com> wrote

> OK, here's a short script, which runs fine on Windows. What do I add
> to have it run on unix as well?

Take a look at my Event Driven programming topic. It contains a
simple key echo program using msvcrt and instructions for Linux
users to convert it to use curses.

>From that you should be able to create a dual platform version.


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


> #!/usr/bin/env python
> #coding=utf-8
>
> try:
>     # windows or dos
>     import msvcrt
>     while True:
>         if msvcrt.kbhit():
>             key = msvcrt.getch()
>             if key == "h":
>                 print "Hello, World!"
>                 break
>     print "Bye, World!"
>
> except ImportError:
>     # assume unix
>     import tty, termios
>
> Dick
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list