Operator Overloading Basics

Tim Chase python.list at tim.thechases.com
Mon Aug 28 12:25:05 EDT 2006


> obj1 = c1(1)
> 
> obj1 + 10 # this works just fine
> 
  10 + obj1 # throws exception

>             Q. What do I have to do to make the following line work?
> 
>                         10 + obj1


http://docs.python.org/ref/numeric-types.html

You want to read the section on __radd__ (and it's other 
__r[whatever]__ variants)

-tkc






More information about the Python-list mailing list