Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is "object.__dict__ is object.__dict__" False?

Tags:

python

If I run the following code in a Python interpreter:

>>> object.__dict__ is object.__dict__
False

Why is the result False?

like image 583
NathaneilCapital Avatar asked Oct 21 '15 14:10

NathaneilCapital


1 Answers

object.__dict__, unlike other __dict__s, returns a mappingproxy object (a dict_proxy in Python 2). These are created on the fly when __dict__ is requested. So as a result, you get a new proxy every time you access object.__dict__. They all proxy the same underlying object, but the proxy is a fresh one all the time. That’s why you can’t get two identical ones.

like image 53
poke Avatar answered Oct 06 '22 11:10

poke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!