Two attributes! Why?
steve at REMOVE-THIS-cybersource.com.au
Tue Dec 2 00:04:45 CET 2008
On Mon, 01 Dec 2008 07:43:44 -0800, Emanuele D'Arrigo wrote:
> On Nov 29, 5:21 am, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> 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.
> Ah! That make sense! Thank you!
> It's a bit of an obscure thing right now. I don't see mention of it in
> the description of the setattr/getattr built-ins:
> Wouldn't be good to have a hint of the issue there?
You seem to assume that name mangling always happens unless the docs say
it doesn't. That's backwards. Name mangling *never* happens except where
the docs say it does.
Hence I can tell you that self.__dict__['__name'] will fail to find a
name-mangled attribute self.__name without even trying it, because I know
dictionary lookups don't do name-mangling either.
More information about the Python-list