Python打印类的属性列表 2014-10-23 10:00

基本介绍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /usr/bin/env python

class a():
    success = True
    message = "abc"
    iValue = 7;

    def json(self):
        return "abc"

def run():
    obj = a()

    memberList = [m for m in dir(obj) \
                           if m[0] != "_" and not callable(getattr(obj, m))]
    _dict = {}
    for m in memberList:
        _dict[m] = getattr(obj, m)
    print _dict

if __name__ == '__main__':
    run()
Tags: #Python    Post on Python