[Python-Dev] Propose rejection of PEP 303 -- Extend divmod() for Multiple Divisors

Tim Peters tim.peters at gmail.com
Fri Jun 17 18:33:32 CEST 2005


About PEP 303, I use divmod for lots (and lots) of things, but I've
got no real use for an extended divmod() either.  -1:  it would be
low-use, confusing clutter.

[Barry]
> Interesting.  Just yesterday I wrote a simple stopwatch-like timer
> script and I found that I needed three divmod calls to convert from
> seconds into a datetime.time object.

You don't need any divmods for that ...

...
> Actually, no, because datetime.time(seconds=50227) throws an exception.

That's right:  the time class models a time of day, not "seconds from
Barry's implied midnight epoch" (or something like that).  What you
wanted was a timedelta instead.  Converting that to a time is then
simplicity itself <wink>:

>>> print (datetime(1, 1, 1) + timedelta(seconds=50227)).time()
13:57:07

You have to go thru a datetime object first because time objects don't
support arithmetic either.  That isn't all bad.  By going thru a
datetime first, it's clear what happens if the number of seconds you
feed in exceeds a day's worth.  You can check for that or ignore it
then, depending on what your app wants (it may or may not be "an
error", depending on the app).


More information about the Python-Dev mailing list