I want to use a construct like this, where a function is defined inside of another and can alter a value defined in the outer function:
def function1():
res = []
def function2():
global res
if (possibleToAnswer):
res.append(answer)
else:
function2()
return res
print (("%s") % function1(para))
It doesn't seem to work. I keep getting unbound bug. Any idea about how to get it to work?
global. Also, your example isn't complete and verifiable because certain parts (e.g.possibleToAnswer) aren't defined in what you've posted.function1as accepting any parameters, yet you call it the parameterpara.