[Python-ideas] datetime.timedelta literals

Pål Grønås Drange paal.drange at gmail.com
Thu Jun 7 07:34:58 EDT 2018


For closure, I've added a package, timeliterals

(env) [pgdr at hostname ~]$ pip install timeliterals
(env) [pgdr at hostname ~]$ python
>>> from timeliterals import *
>>> 3*hours
datetime.timedelta(0, 10800)
>>> 3*minutes
datetime.timedelta(0, 180)
>>> 3*seconds
datetime.timedelta(0, 3)

The source code is at https://github.com/pgdr/timeliterals

I'm not going to submit a patch to datetime at this time, but I will if
people
would be interested.

- Pål

On 5 Jun 2018 13:56, "Jacco van Dorp" <j.van.dorp at deonet.nl> wrote:

> i'd also be pretty simple to implement....
>
> Just list:
> minute = timedelta(minutes=1)
> hour = timedelta(hours=1)
> etc...
>
> and you could import and use them like that. Or if you really want to
> write 5*m, the just from datetime import minute as m
> _______________________________________________
> 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180607/df41067b/attachment-0001.html>


More information about the Python-ideas mailing list