In a class like this:
class F(object):
def __init__(self, x=0):
self.__x = x
def X(self):
return self.__getattribute___('__x')
Is it possible to use __getattribute__
for getting private attributes? Doing such Python 3 says F has no attribute '__x'
. If my class is like this instead:
class F(object):
def __init__(self, x=0):
self.x = x
@property
def x(self):
return self.__x
def X(self):
return self.__getattribute__('x')
__getattribute__
does work. I know private attributes aren't accessible outside of the class; does the first case not work because of something related to that?