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) |
||
Line 35: | Line 35: | ||
[[category:Python]] | [[category:Python]] | ||
[[Category:pywin]] | [[Category:pywin]] | ||
[[Category:Examples]] |
Revision as of 14:22, 12 September 2008
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()