calculate difference between two timestamps [newbie]
nukeymusic
nukeymusic at gmail.com
Sun Dec 18 10:22:23 EST 2011
On 18 dec, 16:01, Peter Otten <__pete... at web.de> wrote:
> nukeymusic wrote:
> > thanks and also thanks to all the others who were so kind to help me
> > out with my first python-script.
> > I tested your alternatives and they work, the only a minor
> > inconvenience is that the first line of the inputfile gets lost i.e.
> > the first timestamp should become zero (seconds)
>
> That should be easy to fix:
>
> >> with open('testfile','r') as f, open('outputfile','w') as g:
> >> first_date, first_rest = parse_line(next(f))
>
> g.write("0 %s" % first_rest)
>
>
>
>
>
>
>
> >> for line in f:
> >> cur_date, rest = parse_line(line)
> >> delta = cur_date - first_date
> >> g.write("%s %s" % (int(round(delta.total_seconds())), rest))
thanks, that solves it, you're too kind
nukey
More information about the Python-list
mailing list