>> object.__dict__ is object.__dic...">

Why is "object .__ dict__ is object .__ dict__" False?

If I run the following code in the Python interpreter:

>>> object.__dict__ is object.__dict__ False 

Why is the result False ?

+8
python
source share
1 answer

object.__dict__ , unlike other __dict__ s, returns a mappingproxy object (a dict_proxy in Python 2). They are created on the fly when __dict__ requested. That way, every time you access object.__dict__ , you get a new proxy server. All of them proxy the same base object, but the proxy server is updated all the time. That is why you cannot get two of the same.

+7
source share

All Articles