A classmate asked about rewriting the built-in dict class, and after some push I became even more vague.
Take the inline dict. I can assign this variable:
>>> dict=5 >>> dict 5
Now I have lost access to the dict (will it be a shader, like in C ++ or is it different?), But I still have access to the class using the built-in .dict. But I can rewrite this as well:
>>> __builtins__.dict = 6 >>> __builtins__.dict 6
But even this does not violate the class itself:
>>> stillDict = {'key': 'value'} >>> stillDict {'key': 'value'}
So why is the class still βworkingβ after I shadowed it? How does the interpreter know that I am making the dictionary with this purpose, and how is the dictionary created because it really does not require __builtins__.dict ?
change Taking this a little further, from the answer of Simeon, who says this, because I create a literal dictionary ...
before overwriting, I can do this:
>>> a = dict() >>> a.items <built-in method items of dict object at 0x0000000002C97C08>
after overwriting the dict and __builtins__.dict , I can do this:
>>> b = {} >>> b.items <built-in method items of dict object at 0x000000000288FC88>
Which leads to the following ... Both of them are still "dict objects", is this a dict class, just using the constructor to create a dict object? Why do I still have access to inline methods when I shadowed the class?
Daniel B.
source share