On Fri, Feb 15, 2019 at 11:58 AM Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
> A function with "microseconds" in the name IMO misleadingly suggests that > it has something closer to microsecond accuracy than a 1-second granularity. > it sure does, but `delta.total_seconds()` is a float, so ms accuracy is preserved. However, if you DO want a "timedelta_to_microseconds" function, it really should use the microseconds field in the timedelta object. I haven't thought it through, but it makes me nervous to convert to floating point, and then back again -- for some large values of timedelta some precision may be lost. Also: _MICROSECONDS_PER_SECOND = 1000000 really? why in the world would you define a constant for something that simple that can never change? (and probably isn't used in more than one place anyway As Alexander pointed out the canonical way to spell this would be: delta / timedelta(microseconds=1) but I think that is less than obvious to the usual user, so I think a: delta.total_microseconds() would be a reasonable addition. I know I use .totalseconds() quite a bit, and would not want to have to spell it: delta / timedelta(seconds=1) (and can't do that in py2 anyway) -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com