optimization with the "compiler" module
Andrew Dalke
dalke at dalkescientific.com
Wed Apr 17 12:37:05 EDT 2002
Philip Swartzleonard:
>In this case, wouldn't 3+7.0+x be a Typeerror or something? Int doesn't
>know how to add with a Strange, and Strange dosen't have an upgrading
>function...
Yeah, it would. First though, 3+7.0 is a float. To get the behaviour
I mentioned, add
__radd__ = __add__
to the class definition.
> or do we assume addition is always commutitive and try '3+x+
>7.0' (effectively), therefore breaking the optimization mentioned by the
>other... =)
Python nor most other languages can assume addition of unknown types
is communitive. After all, "a"+"b"+"c" != "a"+"c"+"b".
Andrew
More information about the Python-list
mailing list