Well, Python does not have encapsulation as a kind of “philosophical” solution, just like we use duck typing. Personally, I see no reason to use private or protected arguments in Python code.
Speaking of your code, it works great with the following getters and setters:
def set_a(self, v): self.a = v def get_a(self): return self.a
if you make the following modification to your last line __ getattribute __ (self, name):
return object.__getattribute__(self, name)
However, you can use the concept of variable protection if you prefix your personal variables with __, as indicated in mhawke. Plus, Daniel's comment points out the limitation of the arguments of your list. You can save the protected "get / set" behavior by adding "private" and "protected" to your personal list.
source share