[Tutor] Time script help sought!

Jacob S. keridee at jayco.net
Tue Jan 11 22:00:00 CET 2005


Would this do the trick?

stringtime = '12:34'  ## This is the column with the time  12:34 is an
example

time = stringtime.split(":")
time = [int(x) for x in time]
time.reverse()
seconds = time[0]+time[1]
try:
    seconds += time[2]
except IndexError:
    pass
print seconds

I'm almost sure there is a better way to do this.

Jacob Schmidt

> Thanks for this Everyone!
>
> Trying to work with all the stuff folks are giving me on this i a have
> come across a problem... down
> the line i notice that some of the times will also have an hour as well
> as in H:M:S (e.g. 1:22:40)
>
> so in some cases i would need to convert H:M:S to sec and some just M:S
>
>
> or should there just be a fun that passes all the times and converts
> them to H:M:S first and
> just appends a 00:  ((e.g. 00:02:07) if there is no hour value?
>
> cheers,
>
> kevin
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



More information about the Tutor mailing list