Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65029
| From | roy@panix.com (Roy Smith) |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Another surprise from the datetime module |
| Date | 2014-01-30 12:32 -0500 |
| Organization | PANIX -- Public Access Networks Corp. |
| Message-ID | <lce2bf$4fo$1@panix2.panix.com> (permalink) |
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) but that doesn't work. Yes, I know I can use strftime, but (as I've mentioned before :-)), that requires dragging up the reference page to figure out what grotty little format string I need. The brute-force print timedelta(seconds=int(td.total_seconds())) is easier than that, but plain old replace() would be even easier.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Another surprise from the datetime module roy@panix.com (Roy Smith) - 2014-01-30 12:32 -0500 Re: Another surprise from the datetime module Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-30 18:03 +0000 Re: Another surprise from the datetime module Neil Cerutti <neilc@norwich.edu> - 2014-01-30 18:36 +0000
csiph-web