[Python-ideas] Add time.time_ns(): system clock with nanosecond resolution

Victor Stinner victor.stinner at gmail.com
Mon Oct 16 03:58:55 EDT 2017


> What if we had a class, say time.time_base.  The user could specify the base
> units (such as "s", "ns", 1e-7, etc) and the data type ('float', 'int',
> 'decimal', etc.) when the class is initialized. (...)

It's easy to invent various funny new types for arbitrary precision.

But I prefer reusing the standard Python int type since it's very well
known and very easy to manipulate. There is not need to modify the
whole stdlib to support a new type. Moreover, we don't have to
"implement a new type".

> The other advantage is that third-party module could potentially subclass
> this with additional options, such as an astronomy module providing an
> option to choose between sidereal time vs. solar time, without having to
> duplicate the entire API.

Using nanoseconds as int doesn't prevent you to convert it to your own
nice class.


More information about the Python-ideas mailing list