[Tutor] Re: Accessing local variables from nested functions.
Andrei
project5 at redrival.net
Sun Feb 13 12:45:42 CET 2005
Karl Pflästerer wrote on Sun, 13 Feb 2005 12:15:03 +0100:
> what's the Python way of accessing local variables in nesting functions? For
> then there's no problem in running such function, but what if I'd like to
> modify var1 so that the change were vissible in p()?
I'd use return in the form of
def p():
v = 3
def q():
return v+1
v = q()
If you need to modify a lot of p-vars inside q, I'd say it's probably wiser
to go with a class and appropriate methods.
--
Yours,
Andrei
=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
More information about the Tutor
mailing list