Operator overloading

MartinRinehart at gmail.com MartinRinehart at gmail.com
Fri Jan 25 13:14:27 EST 2008


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 ..."?




More information about the Python-list mailing list