Need help with Python scoping rules

kj at
Thu Aug 27 14:20:13 CEST 2009

In <mailman.509.1251373513.2854.python-list at> Jean-Michel Pichavant <jeanmichel at> writes:


>a = 5
>b = a # works fine

>    def foo(self):
>       e = 5
>       f = e  #works fine

>It may be solved by creating the class upon the "class" statement. If 
>the class A object is created, then c is added as a property of that 
>object, there's no problem accession one object property with A.c.

I thought one could implement something like

class A:
    c = 5
    d = __thisclass__.c

But apparently this is a *huge* deal.  I'm not sure if the reason
it is a huge deal is that it is technically difficult to implement,
or that there is an implicit "lie" in having something (__thisclass__)
standing for something else that doesn't yet exist (and the potential
errors that may arise from this "lie" in sufficiently unfortunate
code).  Or maybe something else beyond my noobish ken altogether.


More information about the Python-list mailing list