[Python-Dev] PEP 303: Extend divmod() for Multiple Divisors

Guido van Rossum guido@python.org
Tue, 31 Dec 2002 23:22:00 -0500


> Therefore, I consider divmod a waste of code and
> a function to be deprecated ASAP (and since years).

Maybe it wasn't such a good idea.

> Save brain cells, save computation time, and save
> paper and ink of the book writers by dropping divmod!

At this point, any change causes waste, so unless it's truly broken
(which I don't believe) I'm not for changing it.

> Vice versa, if at all, I suggest a built in /% operator
> as a faster equivalen to single / and %, but I believe
> this code can be used more efficiently.
> divmod should be a special case of an algebraic
> extension module and removed from the builtins.

That would have to be //% to be in line with the // operator, of
course.  But I'd rather spend the effort towards making the compiler
smart enough to recognize that divmod is a built-in so it can generate
more efficient code (and I *am* prepared to make the necessary --
slight -- changes to the language so that the compiler can make this
deduction safely).

> divmod does not save computation time, does not
> reduce programming time, does not simplify programs,
> eats paper and code space

I find

  mm, ss = divmod(ss, 60)

easier to read than

  mm, ss = ss//60, ss%60

--Guido van Rossum (home page: http://www.python.org/~guido/)