How can I reach a private variable within the object
问题 I would like to modify an object private variable class Example(): __myTest1 = 1 __myTest2 = 1 def __init__(self): pass def modifyTest(self, name = 'Test1', value): setattr(self, '__my'+name, value); I tried the code above and it's seems that not possible to reach a private variable, AttributeError: Example instance has no attribute '__myTest1' Is there any way to modify a private variable? 回答1: Accessing from outside: e = Example() e._Example__myTest1 # 1 Due to private variable name