擅长:python、mysql、java
<p>如果您跳过几个环,它可以被检索,但不能像<code>A.test.__doc__</code>那样直接通过属性本身来检索,因为描述符的工作方式。在</p>
<pre><code>class classproperty(object):
def __init__(self, getter):
self.getter = getter
def __get__(self, instance, owner):
if instance is None: # instance attribute accessed on class?
return self
return self.getter(owner)
class A(object):
@classproperty
def test(cls):
"test's docstring"
return "Test"
def docstring(cls, methodname):
return getattr(cls, methodname).getter.__doc__
print docstring(A, 'test') # -> test's docstring
</code></pre>