擅长:python、mysql、java
<p>使用<strong>getattr</strong>方法:</p>
<pre><code>class Baz:
a = 'foo'
b = 'bar'
c = 'foobar'
d = 'fubar'
e = 'fubaz'
def __init__(self):
members = [getattr(self,attr) for attr in dir(self) if not attr.startswith("__")]
print members
baz = Baz()
['foo', 'bar', 'foobar', 'fubar', 'fubaz']
</code></pre>