擅长:python、mysql、java
<p>看看这个:</p>
<pre><code>class Test(object):
def __init__(self):
self.a = 5
self.b = 6
def __getattr__(self, key):
return 'created a new key: {}'.format(key)
obj = Test()
print(obj.a, obj.b)
print(obj.c)
</code></pre>
<p>这里,不是返回<code>'created a new key...'</code>,而是创建一个新属性并返回它。在</p>