variable scope

Mark Dickinson dickinsm at gmail.com
Tue Sep 29 06:43:15 EDT 2009


On Sep 29, 11:11 am, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> Mark Dickinson a écrit :
> > On Sep 28, 9:37 am, Bruno Desthuilliers <bruno.
> > 42.desthuilli... at websiteburo.invalid> wrote:
> >> Looks like a bug to me. I Think you should fill a ticket...
>
> > I don't think it's a bug.  Unless I'm missing something,
> > it's the 'names in class scope are not accessible' gotcha,
>
> I would of course expect the class level name "__a" to be unreachable
> from within __init__. What puzzle me is that local name "__a" (*not*
> self.__a)   in the __init__ resolves to the module level name "_uno__a".

Ah.  So I was, of course, missing something. :)  Apologies.

> > The double underscores and name mangling are a red herring:
>
> I beg to disagree. The problem (well... what I think is a problem,
> actually) IS that name mangling is applied to a method *local* variable.

Hmm. The description of name mangling at:

http://docs.python.org/reference/expressions.html#atom-identifiers

indicates (if I'm reading it right) that this behaviour is at
least intentional: it appears that name mangling occurs at an
early stage of source processing.

Yet another reason to avoid name mangling....

Mark



More information about the Python-list mailing list