Need help with Python scoping rules

kj no.email at please.post
Thu Aug 27 08:20:13 EDT 2009


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

>in foo.py:

>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.

kynn



More information about the Python-list mailing list