Understanding the difference between __getattr__ and __getattribute__

I am trying to understand the difference between __getattr__ and __getattribute__, however, I am failing at it. The answer to the Stack Overflow question Difference between __getattr__ vs __getattribute__ says: __getattribute__ is invoked before looking at the actual attributes on the object, and so can be tricky to implement correctly. You can end up in … Read more

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() … Read more