擅长:python、mysql、java
<p>我希望这个死板的简单只读<code>@classproperty</code>装饰器能够帮助人们寻找类属性。</p>
<pre><code>class classproperty(object):
def __init__(self, fget):
self.fget = fget
def __get__(self, owner_self, owner_cls):
return self.fget(owner_cls)
class C(object):
@classproperty
def x(cls):
return 1
assert C.x == 1
assert C().x == 1
</code></pre>