【发布时间】:2014-06-14 05:32:13
【问题描述】:
我很好奇PEP 232(函数的属性)是否也适用于类方法。最后,我认为它没有或者我做错了什么?
Python 2.7.6 (default, Feb 26 2014, 12:07:17)
[GCC 4.8.2 20140206 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def a(self):
... print(self.a.bar)
...
>>> f = Foo()
>>> f.a.bar = "bar"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'instancemethod' object has no attribute 'bar'
【问题讨论】:
标签: python function class methods properties