FAQ
hi all.

suppose we have a program like this one:
-cut-
g = 100

def a():
g = 200
def b():
global g
g = 300
b()
print g

a()
print g
-cut-

this thing prints 200 300, while i really need it to print 300 100.
When I remove 'global g', it prints 200 100, as one should expect.

If curious, the original function parses certain syntax constructing list-based
tree from it.
I do not want to pollute real global namespace with function-specific subprograms
and variables..

So the question is, how to access function's variables from its nested function?
Python version is 2.2.

The other question - will there be (or already is) in Python something similar in
functionality to variant types from FPLs?
not counting different perversions with checking for None...

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedFeb 26, '03 at 10:42a
activeFeb 26, '03 at 5:40p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase