Class scoping problem...
Fredrik Lundh
effbot at telia.com
Tue Sep 26 12:34:32 EDT 2000
Simon wrote:
> Take the following:
>
> class Foo:
>
> def __init__(self):
> self.bar = 1
>
> def baz(self):
>
> def quix():
> return self.bar
>
> return quix()
how about:
= def baz(self):
= return self.quix()
=
= def quix(self):
= return self.bar
or did you perhaps mean:
> def baz(self):
>
> def quix():
> return self.bar
>
> return re.sub(..., quix, ...)
in which case:
= def baz(self):
= return re.sub(..., self.quix, ...)
=
= def quix(self):
= return self.bar
should do the trick.
(summary: "x = self.quix; x(arg)" is the same thing as
"self.quix(arg)" -- "x" is known as a "bound method")
or did I miss something?
</F>
More information about the Python-list
mailing list