Python: why is __dict__ attribute not in built-in class instances

前端 未结 2 601
囚心锁ツ
囚心锁ツ 2020-12-03 15:36

If my understanding of the Python data model is correct, both classes and class instances have associated __dict__ objects which contain all the attributes. Ho

相关标签:
2条回答
  • 2020-12-03 15:53

    Instances of types defined in C don't have a __dict__ attribute by default.

    0 讨论(0)
  • 2020-12-03 15:55

    Just to add to this:

    You can get the equivalent of a read only __dict__ using this:

    {s:getattr(x,s) for x in dir(x)}
    
    0 讨论(0)
提交回复
热议问题