[ale] 4 way timer
Ed Cashin
ecashin at noserose.net
Sun Feb 22 22:10:04 EST 2009
OK. Assuming you're counting up and that you just want
to start a new timer each time, here's a little python that does
N timers, starting when you launch it. You hit enter to stop
the last timer and start the next one, and you do control-D to
stop the last timer and print them all out.
Example run:
ecashin at ed-cashins-computer ecashin$ ~/src/python/time4
2009-02-22 22:07:02.377053
2009-02-22 22:07:05.681020
2009-02-22 22:07:13.513047
2009-02-22 22:07:13.889052
2009-02-22 22:07:14.297063 ^D
timer 1: 0:00:02.872000
timer 2: 0:00:03.303967
timer 3: 0:00:07.832027
timer 4: 0:00:00.376005
timer 5: 0:00:00.408011
ecashin at ed-cashins-computer ecashin$
I just started learning python, so any python geeks feel free
to make suggestions about the following. The thing is, my
MacBook runs 2.3.5, so I have to stay away from new stuff.
Well, my debian systems have a kind of old python, too, I
think.
ecashin at ed-cashins-computer ecashin$ cat ~/src/python/time4
#! /usr/bin/env python
import sys
from datetime import datetime
a = [datetime.now()]
while 1:
try:
s = raw_input()
except EOFError:
break
t = datetime.now()
print t,
sys.stdout.flush()
a.append(t)
print ''
i = 1
while i < len(a):
print "timer %2d: %s" % (i, a[i] - a[i-1])
i += 1
ecashin at ed-cashins-computer ecashin$
--
Ed Cashin <ecashin at noserose.net>
More information about the Ale
mailing list