pythonのクラスの変数名取得
826 ワード
class A(object):
name = None
number = 123
sex = 'man'
def a(self):
print dir(A)
for over_name in dir(A):
if not over_name.startswith("_"):
print over_name
if __name__ == '__main__':
a = A()
a.a()
出力結果:
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a', 'name', 'number', 'sex']
a
name
number
sex