I know what data mangling in Python is in general and what its purpose is, but there is one subtle aspect I would like to clarify.
Let's say we have a class:
class P:
def __init__(self):
self.x = 10
self.__y = 20
def get_y(self):
return self.__y
p = P(); p.__dict__ now has the key _P__y so this is where the data mangling occurred.
My question is, though, how do we access the attribute inside get_y given that there is no __y key in __dict__?
I have a faint guess that there is some magic going on in __getattribute__ and then, after getting AttributeError, in __getattr__.
This confusion makes me think that I don't have a 100% understanding of what __init__ does under the hood.