Message75892
| Author |
vstinner |
| Recipients |
amaury.forgeotdarc, belopolsky, jribbens, vstinner, webograph |
| Date |
2008年11月14日.21:59:42 |
| SpamBayes Score |
5.9149826e-08 |
| Marked as misclassified |
No |
| Message-id |
<200811142258.42863.victor.stinner@haypocalc.com> |
| In-reply-to |
<d38f5330811141035g14d54942ied933c737b057138@mail.gmail.com> |
| Content |
> def formatTimedelta(delta):
> return "{0}h {1}min {2}sec".format(*str(delta).split(':'))
OMG, this is ugly! Conversion to string and reparse the formatted text :-/
Your code doesn't work with different units than hours, minutes or seconds:
['4 days, 1', '32', '01']
>>> str(timedelta(hours=1, minutes=32, seconds=1, microseconds=2)).split(":")
['1', '32', '01.000002']
> or you can convert delta to time using an arbitrary anchor date
> and extract hms that way:
How? I don't understand your suggestion.
> (depending on your needs you may want to add delta.days*24 to the hours)
The goal of the new operators (timedelta / timedelta, divmod(timedelta,
timedelta), etc.) is to avoid the use of the timedelta "internals" (days,
seconds and microseconds attributes) and give a new "natural" way to process
time deltas. |
|