Operator overloading

Diez B. Roggisch deets at nospam.web.de
Fri Jan 25 19:33:03 CET 2008


MartinRinehart at gmail.com schrieb:
> If it were my choice, the plus sign would do this:
> 
> def itemadd( i1, i2 ):
>     if ( type(i1) == str ) or ( type(i2) == str ):
>         return str(i1) + str(i2)
>     else:
>         return i1 + i2
> 
> I'd like to redefine it so it works my way but operator overloading
> seems strictly confined to classes I create. Is there a way? Or do I
> just have to grump, "Even a kludge like Perl ..."?
> 

No, there is no way. You would change general interpreter behavior if 
you could set arbitrary operators for predefined types.

Start grumping...

Diez



More information about the Python-list mailing list