global statement and scoping

J

jochen.stier

Hi everyone,


I am compiling the following script using Py_CompileString


def compute(node):
#global compute

iter = node.getChild(0)
while iter:
if isinstance(iter, Group):
compute(iter)
print iter
iter = iter.next

compute(self.a0)


The I evaluate the script using PyEval_EvalCode and get a ''global name
"compute" is not
defined' error at the line of the recursive call. When I comment in the
"global" statement at the beginning of the function then everything
works fine. What's strange is the once I comment out the statement
again it still works... Somewhere something is written into a
dictionary in dunno where ?

Is it normal to have the global statement at the beginning of a
function like that ?

Cheers
Jochen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,291
Messages
2,571,455
Members
48,132
Latest member
KatlynC08

Latest Threads

Top