I am a bit confused by this behavior (using python 3.2):
class Bar:
pass
bar = Bar()
bar.__cache = None
print(vars(bar)) # {'__cache': None}
class Foo:
def __init__(self):
self.__cache = None
foo = Foo()
print(vars(foo)) # {'_Foo__cache': None}
I've read up a bit on how double-underscores cause attribute names to be "mangled", but I would have expected the same name-mangling in both cases above.
What is the meaning of a single- and a double-underscore before an object name?
Any ideas what's going on here?