> What about > > 2.5*h - 14*min + 9300*ms * 2 That doesn't seem feasible to implement, however, that is essentially how the Pint [1] module works:
import pint u = pint.UnitRegistry() (2.5*u.hour - 14*u.min + 9300*u.ms) * 2 # <Quantity(4.5385, 'hour')> ((2.5*u.hour - 14*u.min + 9300*u.ms) * 2).to('sec') # <Quantity(16338.6, 'second')> > However why be limited to time units ? One would want in certain > application to define other units, like meter ? Would we want a litteral > for that ? Pint works with all units imaginable: Q = u.Quantity Q(u.c, (u.m/u.s)).to('km / hour') # <Quantity(3.6 speed_of_light, 'kilometer / hour')> However, the idea was just the six (h|min|s|ms|us|ns) time literals; I believe time units are used more often than other units, e.g. in constructs like while end - start < 1min: poll() sleep(1s) # TypeError sleep(1s.total_seconds()) # works, but ugly [1] https://pypi.org/project/Pint/ Best regards, Pål Grønås Drange
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/