擅长:python、mysql、java
<p><code>@classmethod</code>可能是您在这里的最佳选择。在</p>
<pre><code>class First:
@classmethod
def name(cls):
return "john" if cls.prop() == "custom" else "steve"
class Second(First):
@classmethod
def prop(cls):
return "custom"
print(Second.name()) # -> john
class Second(First):
@classmethod
def prop(cls):
return "notcustom"
print(Second.name()) # -> steve
</code></pre>
<p>(另外,不要使用<code>property</code>,因为这已经是语言中的关键字了</p>