I have a class with private attribute
class DoGood():
__prv = "i m private"
def __init__(self):
self.default_string = self.__prv
def say_it_aloud(self):
print self.default_string
I m trying to access the private attribute from python-cli
>>> from sample import DoGood
>>> obj = DoGood()
>>> obj.__prv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: DoGood instance has no attribute '__pro'
Since its private i m not able to access it But when i try to assign a value i m able to do it
>>> obj.__prv = "changed in subclass"
>>> obj.say_it_aloud()
i m private
However the value inside the class object has not changed. But why i m able to assign it do it serve any purpose