Python Class Members Initialization

前端 未结 5 1757
后悔当初
后悔当初 2020-11-29 03:37

I have just recently battled a bug in Python. It was one of those silly newbie bugs, but it got me thinking about the mechanisms of Python (I\'m a long time C++ programmer,

5条回答
  •  [愿得一人]
    2020-11-29 04:32

    When you access attribute of instance, say, self.foo, python will first find 'foo' in self.__dict__. If not found, python will find 'foo' in TheClass.__dict__

    In your case, dict1 is of class A, not instance.

提交回复
热议问题