By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

Attribute value of instance method non-modifiable?

P: n/a

I just stumbled over this:
..>>> class test(object):
.... def t(): pass
.... t.testval = 1
..>>> test.t
<unbound method test.t>
..>>> test.t.testval
..>>> 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']
test.t.im_func.testval = 2
test.t.testval 2

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?

Oct 26 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.