Time script help sought!

kpp9c kp8 at mac.com
Wed Jan 12 10:03:31 EST 2005


paul that is awesome.... so much better than what i did which was lamo
brute force method. I formmatted and reformatted my input data and
stuffed it in a HUGE dictionary.... it was stupid and kludgy.... i hope
to study all these approaches and learn something.... here's what i
came up with ... with my pea sized brain...

#!/usr/bin/env python

# New in version 2.3 is the 'datetime' module (see standard library
reference)
# http://www.python.org/doc/lib/module-datetime.html

import datetime

inseqs = { (1) : ['DAT_1', '01', '00:00:23', '00:08:23'],
(2) : ['DAT_1', '02', '00:08:23', '00:09:41'],
(513) : ['DAT_75', '10', '00:59:55', '01:11:05'],
(514) : ['DAT_75', '11', '01:11:05', '01:16:15'],
(515) : ['DAT_75', '12', '01:16:15', '01:34:15'],
(516) : ['DAT_75', '13', '01:34:15', '01:45:15'],
(517) : ['DAT_75', '14', '01:45:15', '01:48:00'] }


mykeys = inseqs.keys()      # first make a copy of the keys
mykeys.sort()               # now sort that copy in place

for key in mykeys:
event = inseqs[key]
print '\n','Item #', key, event
TD = datetime.timedelta
h, m, s = event[2].split(':')
zero_adjust = TD(hours=int(h), minutes=int(m),seconds=int(s))
#
print ' Q___ ', key, event[:2], ': ',
for item in event[2:]:
hrs, mins, secs, = item.split(':')
time1 = TD(hours=int(hrs), minutes=int(mins),seconds=int(secs))
print time1 - zero_adjust,
        
    print




More information about the Python-list mailing list