New Python 3.0 string formatting - really necessary?

Duncan Booth duncan.booth at invalid.invalid
Sun Dec 21 10:30:34 EST 2008


Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:

>> a+b+c+d might execute a.__add__(b,c,d) allowing more efficient string
>> concatenations or matrix operations, and a%b%c%d might execute as
>> a.__mod__(b,c,d).
> 
> But that needs special casing strings and ``%`` in the comiler, because 
> it might not be always safe to do this on arbitrary objects.  Only in 
> cases where the type of `a` is known at compile time and ``a % b`` 
> returns an object of ``type(a)``.
> 
I could be wrong, but I don't see that would be the case.

I think it would be safe (in this hypothetical universe) any time that 'a' 
had a method __mod__ which accepted more than one argument.

It might be simpler if I'd suggested an imaginary __mmod__ method so the 
opcode for multiple-mod could check for that method or fall back to doing 
mod of the first two values and then mmod of the result and any remaining 
values until only two remain.



More information about the Python-list mailing list