On Fri, 28 Nov 2008 19:22:42 -0800, Emanuele D'Arrigo wrote: > Hi everybody, > > I'm having a naming/scoping/mangling issue. I have a class like this: > > class MyClass(object): > __init__(self): > self.__myAttribute = None > > def myMethod(self, aValue): > attributeName = "__myAttribute" > setattr(self, attributeName, aValue) > > It all looks good to me but when I use a debugger I find that > > - myClass._MyClass__myAttribute = None > > and > > - myClass.__myAttribute = aValue > > I can't quite understand why.
This is a side-effect of name-mangling. Double-underscore names are only mangled when they are referred to directly as attributes, not when they are passed to setattr, getattr etc. Those functions don't do any name mangling. -- Steven -- http://mail.python.org/mailman/listinfo/python-list