New Python 3.0 string formatting - really necessary?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Sun Dec 21 08:34:35 EST 2008
On Sun, 21 Dec 2008 12:45:32 +0000, Duncan Booth wrote:
> You seem to have made an unwarranted assumption, namely that a binary
> operator has to compile to a function with two operands. There is no
> particular reason why this has to always be the case: for example, I
> believe that C# when given several strings to add together optimises
> this into a single call to a concatenation method.
>
> Python *could* do something similar if the appropriate opcodes/methods
> supported more than two arguments:
>
> 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)``.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list