Issue with new-style classes and operators
Jan Decaluwe
jan at jandecaluwe.com
Mon Nov 25 07:21:37 EST 2002
Hi:
I'm confused by the following behavior of new-style classes
and operators:
class MyInt(object):
def __init__(self, val):
self.val = val
def __getattr__(self, attr):
return getattr(self.val, attr)
> python
Python 2.2.2 (#1, Oct 16 2002, 19:59:11)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from MyInt import MyInt
>>> a = MyInt(3)
>>> a.__add__(4)
7
>>> a + 4
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unsupported operand types for +: 'MyInt' and 'int'
I don't think is can be the intention. Or can it?
Regards, Jan
--
Jan Decaluwe
Losbergenlaan 16
B-3010 Leuven
mailto:jan at jandecaluwe.com
More information about the Python-list
mailing list