S
Stefan Behnel
Hi!
I just stumbled over this:
..>>> class test(object):
.... def t(): pass
.... t.testval = 1
....
..>>> test.t
<unbound method test.t>
..>>> test.t.testval
1
..>>> test.t.testval = 2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'instancemethod' object has no attribute 'testval'
..>>> dir(test.t)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func',
'im_self', 'testval']
While I understand that a function is different from an instance method, it is
rather far from intuitive that the instance method provides read access to the
attribute of the enclosed function but not write access.
Does anyone know if this is a deliberate implementation decision? Is there any
reasoning behind that?
Stefan
I just stumbled over this:
..>>> class test(object):
.... def t(): pass
.... t.testval = 1
....
..>>> test.t
<unbound method test.t>
..>>> test.t.testval
1
..>>> test.t.testval = 2
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'instancemethod' object has no attribute 'testval'
..>>> dir(test.t)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__get__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__setattr__', '__str__', 'im_class', 'im_func',
'im_self', 'testval']
While I understand that a function is different from an instance method, it is
rather far from intuitive that the instance method provides read access to the
attribute of the enclosed function but not write access.
Does anyone know if this is a deliberate implementation decision? Is there any
reasoning behind that?
Stefan