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

Barry Warsaw barry at python.org
Fri Jun 17 15:50:38 CEST 2005


On Fri, 2005-06-17 at 05:57, Raymond Hettinger wrote:
> This PEP has been open for two and half years without generating
> discussion or support.

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.  This PEP might have come in handy
there, but OTOH, I'm not so sure that's enough justification to accept
the PEP.

> Its primary case (converting cumulative seconds into a tuple days,
> hours, minutes, and seconds) is a bit wanting because it doesn't
> generalize to months and years.  That need is already met in a more
> robust and flexible way by date and time specific modules.

Actually, no, because datetime.time(seconds=50227) throws an exception. 
But in my specific case, I didn't find the need for three divmod calls
nearly as frustrating as the lack of a datetime.time.fromseconds() call.

> More importantly, the gain in succinctness is offset by a loss of
> clarity.  Consider:
> 
>    dist, inches = divmod(dist, 12)
>    yards, feet = divmod(dist, 3)
> 
> versus a proposed:
> 
>    yards, feet, inches = divmod(dist, 3, 12)
> 
> The latter form makes it difficult to visually confirm the correct
> number of target variables.  Likewise, it is not at all obvious that the
> order of the 3 and 12 are correct.

I agree.  My three divmod solution is perfectly readable and simple to
write.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20050617/a6d19c01/attachment.pgp


More information about the Python-Dev mailing list