Difference between revisions of "Alarm.py"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (New page: =Simple= <pre> #!/usr/bin/env python try: import os import sys import time import msvcrt import winsound except ImportError, error: sys.stdout.write('ImportError:...) |
PeterHarding (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 34: | Line 34: | ||
[[category:Python]] | [[category:Python]] | ||
[[Category: | [[Category:PyWin]] | ||
[[Category:Examples]] |
Latest revision as of 17:57, 23 October 2009
Simple
#!/usr/bin/env python try: import os import sys import time import msvcrt import winsound except ImportError, error: sys.stdout.write('ImportError: %s' % error) sys.exit(1) def main(): try: alarm(*map(float, sys.argv[1:])) except: sys.stdout.write(os.path.basename(sys.argv[0])) sys.stdout.write(' <hours> <minutes> <seconds>') def alarm(hours, minutes, seconds): time.sleep(abs(hours * 3600 + minutes * 60 + seconds)) while msvcrt.kbhit(): msvcrt.getch() while not msvcrt.kbhit(): winsound.Beep(440, 250) time.sleep(0.25) if __name__ == '__main__': main()