python中的__dict__

python 类或对象的__dict__包存了类或对象内部所有属性和方法对应的字典

class A():
    aname = "AAA"

    @classmethod
    def c_fn(cls):
        pass

    @staticmethod
    def sta_fn():
        pass

    def __init__(self):
        self.name = "aa"

    def my_fn(self):
        pass

a = A()

print(A.__dict__)   # {'__module__': '__main__', 'aname': 'AAA', 'c_fn': <classmethod object at 0x0000017CCC89EFD0>, 'sta_fn': <staticmethod object at 0x0000017CCC89EFA0>, '__init__': <function A.__init__ at 0x0000017CCC89B820>, 'my_fn': <function A.my_fn at 0x0000017CCC89B8B0>, '__dict__': <attribute '__dict__' of 'A' objects>, '__weakref__': <attribute '__weakref__' of 'A' objects>, '__doc__': None}

print(a.__dict__)   # {'name': 'aa'}

 

posted @ 2020-12-27 15:47  foreast  阅读(294)  评论(0编辑  收藏  举报