[Tutor] How can I access a variable outside a class definition?
asgard
asgard at hellnet.cz
Sat Sep 29 18:29:16 EDT 2001
On Sat, 29 Sep 2001, Kirby Urner wrote:
> Classes have access to variables defined outside of them, e.g.
>
> >>> c = 10 # defined outside (e.g. returned by yr Complex.Add())
>
> >>> class C:
> def func(a,b):
> return a+b+c
> func =staticmethod(func)
>
>
> >>> C.func(1,2)
> 13
>
>
> is legal in 2.2 (the staticmethod syntax allows C to not
> have a self -- a new breed of soulless classes is afoot).
This also seems missing from the 2.2a3 documentation (built-in function?).
I am also missing a description of iterators and generators and other
new features.
Thank you,
Jan Samohyl
More information about the Python-list
mailing list