[Tutor] Want to use msvcrt.getch() but can't import msvcrt (original) (raw)
Dick Moores rdm at rcblue.com
Sat Jul 17 09:01:42 CEST 2004
- Previous message: [Tutor] Why does counting to 20 million stress my computer?
- Next message: [Tutor] Want to use msvcrt.getch() but can't import msvcrt
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
A week ago or so I asked how I might enable pausing my timer.py. Alan Gauld suggested looking at the mscvrt module (which is available for Windows) and mscvrt.getch(). He also referred me to a page of his tutorial, <http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/tutevent.htm>
This seems to be just what I'm looking for, but when I import mscvrt I get "ImportError: No module named mscvrt".
So I can't even run the scripts on his page.
For your instructing convenience here's a bare-bones version of my timer:
============================= #timer_simple.py import time #import mscvrt # gets "ImportError: No module named mscvrt"
secondsToTime = int(raw_input("Seconds: ")) timeStart = time.time() timeNow = 0 while True: time.sleep(.25) timeNow = time.time() secondsPassed = timeNow - timeStart secondsLeft = secondsToTime - secondsPassed if secondsPassed >= secondsToTime: break
print "TIME'S UP! %d seconds have passed" % secondsToTime print "Actual time is %f" % (timeNow - timeStart)
Alan suggested the time.sleep(.25) line to slow the loop down so I can do something else with my computer while using the timer. He said to create a "guard condition" by making the timeNow = time.time() line into an if statement. If was able to import mscvrt and use mscvrt.getch() I suppose I could figure this out by experimenting, but I can't even do that.
I'd also like to build in a way to stop the time in mid-timing, without resort to ^C or ^D. I suppose getch() is the thing to use here also.
BTW I'm using Python 2.3.4 on Windows XP.
Do I need to download the mscvrt from somewhere?
Help, please?
Thanks, tutors.
Dick Moores
- Previous message: [Tutor] Why does counting to 20 million stress my computer?
- Next message: [Tutor] Want to use msvcrt.getch() but can't import msvcrt
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]