Time constants module - standard-library fodder?

Dan Bishop danb_83 at yahoo.com
Sat May 31 19:34:25 EDT 2003


Ben Finney <bignose-hates-spam at and-zip-does-too.com.au> wrote in message news:<slrnbde06f.k98.bignose-hates-spam at iris.polar.local>...
> Howdy,
> 
> Many programmers in many languages break the "use named constants" rule,
> but one of the most egregious examples seems to be constants for number
> of seconds in an hour, day, week, etc.
> [snip]
> Is there a better way?  A standard module I've missed?

In Python 2.3, yes.  Take at look at the datetime.timedelta class. 
It's even better than a list of conversion factors, because, e.g.

>> datetime.timedelta(minutes=5) == datetime.timedelta(seconds=300)
True

without the need to explicity add a *60 to the left-hand side.




More information about the Python-list mailing list