class A(object):
def __init__(self):
self.__my_var = 'a'
class B(A):
def foo(self):
print self.__my_var
error:
AttributeError: 'B' object has no attribute '_B__my_var'
You learn something new everyday. Apparently prefixing with __ in classes in python causes the interpreter to mangle the name. This makes a "private" variable. Whereas if you use the prefix _, it doesn't mangle stuff so it's a "protected" variable.
Python still baffles me. It feels like a high-level language, but it continuously exposes me to things like the details on how name mangling works, how name resolution works, or other details that aren't generally of interest. Oh the other hand, you get stuff like
list comprehensions.