Another surprise from the datetime module
Neil Cerutti
neilc at norwich.edu
Thu Jan 30 13:36:34 EST 2014
On 2014-01-30, Roy Smith <roy at panix.com> wrote:
> I was astounded just now to discover that datetime.timedelta
> doesn't have a replace() method (at least not in Python 2.7).
> Is there some fundamental reason why it shouldn't, or is this
> just an oversight?
>
> My immediate use case was wanting to print a timedelta without
> the fractions of seconds. The most straight-forward is:
>
> print td.replace(microseconds=0)
That would be nice.
In the meantime, this works for your use case:
td -= td % timedelta(seconds=1)
--
Neil Cerutti
More information about the Python-list
mailing list