Inserting class namespace into method scope
Günther Dietrich
gd.usenet at spamfence.net
Sat Nov 20 11:45:32 EST 2010
Steven D'Aprano <steve at REMOVE-THIS-cybersource.com.au> wrote:
>I find myself having need of a class where the class scope is included in
>the scope of methods in the class. A simple example from Python 3.1:
>
>x = "outside"
>
>class Magic:
> x = "inside"
> def method(self):
> return x
>
>
>I would like Magic().method() to return "inside" rather than "outside".
Try this instead:
return self.x
Best regards,
Günther
More information about the Python-list
mailing list