[Tutor] Time script help sought!

kevin parks kp8 at mac.com
Wed Jan 12 16:08:02 CET 2005


thanks everyone... I will look at all the various appraoches folks came 
up with and see what i can learnn from them. I ended doing something 
lame -- a 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 
that may help me do something that is more flexible about the input 
data and is more elegant..... 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 Tutor mailing list