Why nested scope rules do not apply to inner Class?

Maric Michaud maric at aristote.info
Wed Aug 13 20:00:36 EDT 2008


Le Wednesday 13 August 2008 21:04:30 Rhamphoryncus, vous avez écrit :
> class X(object):
>     foo = 42
>
>     def bar(self):
>         print foo
>         print self.foo
> X.foo = 7

Yes this is a problem, function could not bind their free vars to the class 
namespace without introducing a subtle incompatibility with actual code.

This is exactly this case which would be a problem (your example raise an 
error and is not exactly a "running code"):

G = 1
class A(object) :
    G = 0
    def f(self) : return G

-- 
_____________

Maric Michaud



More information about the Python-list mailing list