Why no lexical scoping for a method within a class?

Richard Brodie R.Brodie at rl.ac.uk
Wed Dec 17 12:17:02 EST 2008


"walterbyrd" <walterbyrd at iname.com> wrote in message 
news:518b9dd9-69c5-4d5b-bd5f-ad567be6249b at b38g2000prf.googlegroups.com...

> However in the methods are within a class, the scoping seems to work
> differently.

Not really, self is a formal parameter to the function. It would be
a strange language where a function's own arguments weren't in scope.

>    def b(self):
>        print self.x

Try changing it to:

def b(somethingotherthanself):
    print self.x






More information about the Python-list mailing list