[Python-ideas] datetime.timedelta literals

Chris Barker chris.barker at noaa.gov
Mon Jun 4 17:50:43 EDT 2018


On Mon, Jun 4, 2018 at 1:59 PM, Pål Grønås Drange <paal.drange at gmail.com>
wrote:

> For the general user-defined literals, here are some example use cases:
>

I kind of like the idea of user-defined literals, but:


> Yes, we could write all these as easily as function calls,
>
> deg(90)
> celsius(20)
> center('my string')  # or 'my string'.center(80)
>
> But somehow it seems nicer to write 42_km than 12 * pint.UnitRegistry().km
>

how about?

from pint import km

42*km

still not as nice as 42_km, though only by a bit....

So maybe you could propose adding:

seconds
minutes
hours
days

to the datetime module, and then we could write:

60*seconds == 1*minutes

Without any changes to the language at all.

-CHB







>
>
> - Pål
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>


-- 

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.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180604/4a512427/attachment.html>


More information about the Python-ideas mailing list