Need help with Python scoping rules

kj at
Wed Aug 26 16:09:57 CEST 2009

In <16b72319-8023-471c-ba40-8025aa6d462e at> Carl Banks <pavlovevidence at> writes:

>> First, one of the goals of OO is encapsulation, not only at the
>> level of instances, but also at the level of classes. =A0Your comment
>> suggests that Python does not fully support class-level encapsulation.

>I can't answer this, I don't even know what you are talking about.

Yes, you do.  As I said in another post, Python offers some degree
of class-level encapsulation (e.g. class variables).  But it is
limited by the fact that these class-encapsulated elements can't
always be accessed from within the class itself, which is kind of

>1. One of the key aspects of Python's design is that attributes must
>be accessed explicitly with dot notation.  Accessing class scopes from
>nested functions would (seemingly) allow access to class attributes
>without the dotted notation.  Therefore it is not allowed.

It would be trivial to define a keyword (e.g. this, or if you
prefer, __this__), valid only within a class statement, and that
the interpreter would recognize as "the current class", even before
this class is full defined.


More information about the Python-list mailing list