擅长:python、mysql、java
<p>不如就:</p>
<pre><code>def sasquatchicorn(name):
return property(lambda self: getattr(self, name) + ' sasquatch',
lambda self, val: setattr(self, name, val + ' unicorns'))
class Foo(object):
bar = sasquatchicorn('_bar')
baz = sasquatchicorn('_baz')
</code></pre>
<p>一般来说:</p>
^{pr2}$
<p>或者,只需做更多的工作,就可以使用完整描述符协议,如<a href="https://stackoverflow.com/a/10149431/344821">agf's answer</a>中所述。在</p>