Attributes and built-in types
Dave Opstad
opstad at batnet.com
Fri Apr 1 15:42:17 EST 2005
Is it just an implementation limitation that attributes cannot be
assigned to instances of internal types?
---------------------------
>>> x = 4
>>> type(x)
<type 'int'>
>>> class Test(int):
... pass
...
>>> y = Test(4)
>>> type(y)
<class '__main__.Test'>
>>> y.someattr = 10
>>> x.someattr = 10
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'int' object has no attribute 'someattr'
---------------------------
When I did a dir(int) there was no __dict__ entry, but a dir(Test)
showed a __dict__entry, which is why (presumably) the attribute
assignment worked for Test but not for int.
Just curious...
Dave
More information about the Python-list
mailing list