[Python-ideas] datetime.timedelta literals
clint.hepner at gmail.com
Mon Jun 4 09:17:51 EDT 2018
> On 2018 Jun 4 , at 9:08 a, Giampaolo Rodola' <g.rodola at gmail.com> wrote:
> IMO datetimes are not common enough to deserve their own literals. It would make the language more complex and harder to learn for a relatively little benefit. This would probably make more sense as a third party lib:
> >>> import datetimeutils
> >>> datetimeutils.interpretstr("2.5h - 14min + 9300ms")
> Both the string and the possibility to specify function arguments would give you way more expressiveness than language literals.
Agreed. I'll add that interpretstr probably isn't necessary; the constructor for timedelta already lets you write
>>> datetime.timedelta(hours=2.5, minutes=-14, milliseconds=9300)
datetime.timedelta(0, 8169, 300000)
Further, I'd argue that such involved timedelta instances are rarely instantiated
explicitly, resulting instead from datetime arithmetic.
More information about the Python-ideas