Why are Python's 'private' methods not actually private?
问题 Python gives us the ability to create \'private\' methods and variables within a class by prepending double underscores to the name, like this: __myPrivateMethod() . How, then, can one explain this >>> class MyClass: ... def myPublicMethod(self): ... print \'public method\' ... def __myPrivateMethod(self): ... print \'this is private!!\' ... >>> obj = MyClass() >>> obj.myPublicMethod() public method >>> obj.__myPrivateMethod() Traceback (most recent call last): File \"\", line 1, in