PEP 303: Extend divmod() for Multiple Divisors

"Martin v. Löwis" martin at v.loewis.de
Tue Dec 31 15:35:04 EST 2002


Bjorn Pettersen wrote:
> I'm having problems understanding the description too... Maybe you could explore 
> _why_ it feels right to you -- as it stands I'd probably have to look up the 
> order every time I wanted to use it...

The use case for this feature will yield values in some (irregular) 
positioning system (e.g. days, hours, minutes, seconds). It is common to 
list such values with the most significant digit (days) first, and it is 
(IMO) intuitive if the bases are listed in the same order (i.e. 24, 60, 
60). The computation will start from the right end, just as it does in a 
regular positioning system (445 decimal in base 16: divmod(445, 16) => 
(27, 13), so the last digit is 13; divmod(27, 16) => (1, 11)
-> 445 == 0x1BD).

Regards,
Martin





More information about the Python-list mailing list