[Python-ideas] datetime.timedelta literals

Robert Vanden Eynde robertve92 at gmail.com
Tue Jun 5 06:48:55 EDT 2018


second, minute, hour (singular) timedelta objects in the module are a good
idea, one could do 5 * minute to get a timedelta or one could do value /
minute to get a float.

a = datetime.now()
b = datetime(2018, 2, 3) + 5 * minute
print((a - b).total_seconds())
print((a - b) / minute)



Le mar. 5 juin 2018 à 10:23, Jacco van Dorp <j.van.dorp at deonet.nl> a écrit :

> 2018-06-05 10:08 GMT+02:00 Pål Grønås Drange <paal.drange at gmail.com>:
> >> You can't import literals. They're syntax, not just bound names.
> >
> > I'm way out of my comfort zone now, but the parser could for
> > `123.45_f`
> > give
> > `__literal_f__(123.45)`
> > and then that function should be imported.
> >
> > I'm sure this idea has many shortcomings that I don't see, but that was
> the
> > reason why I wanted to import stuff.
> >
> > Pål
>
> Before your code is executed, python scans your entire file for syntax
> errors. Since 123.45_f is currently not a valid literal, it'll just
> print a syntax error without even looking at your imports.
>
> To change that, the very core of python would need to look completely
> different. It'd be a metric fuckton of work for a whole lot of people.
> Im not a core dev myself or anything, but i'm pretty confident that
> this isn't going to happen for a rather minor need like this.
> _______________________________________________
> 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/20180605/bee1cbe6/attachment.html>


More information about the Python-ideas mailing list