consider my class mint
class mint(object):
def __init__(self, i):
self.i = i
def __add__(self, other):
o = other.i if isinstance(other, mint) else other
return mint(1 + self.i + o)
def __repr__(self):
return str(self.i)
It's designed to do another kind of addition.
a = mint(1)
a + 1 + 2
6
However, adding while my object is on the right doesn't work.
1 + a
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-519-8da568c0620a> in <module>() ----> 1 1 + a
TypeError: unsupported operand type(s) for +: 'int' and 'mint'
Question: How do I modify my class such that 1 + a
will work?