I found it fun to be able to write minutes(50) alongside with 50 * minutes so I did that :
from datetime import date, time, datetime, timedelta class CallableTimedelta(timedelta): def __call__(self, x): return self * x seconds, milliseconds, microseconds, days, hours, minutes, weeks = (CallableTimedelta(**{x:1}) for x in ('seconds', 'milliseconds', 'microseconds', 'days', 'hours', 'minutes', 'weeks')) print(minutes(50) / seconds) # 3000.0 print(50 * minutes / seconds) # 3000.0 print(minutes(50).total_seconds()) # 3000.0 2018-06-07 13:34 GMT+02:00 Pål Grønås Drange <paal.dra...@gmail.com<mailto:paal.dra...@gmail.com>>: For closure, I've added a package, timeliterals (env) [pgdr@hostname ~]$ pip install timeliterals (env) [pgdr@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.d...@deonet.nl<mailto:j.van.d...@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@python.org<mailto:Python-ideas@python.org> https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/ _______________________________________________ Python-ideas mailing list Python-ideas@python.org<mailto:Python-ideas@python.org> https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/