this is my code :
def a():
print aa
def b():
aa = 'aaaa'
a()
b()
it show error :
Traceback (most recent call last):
File "g.py", line 12, in <module>
b()
File "g.py", line 10, in b
a()
File "g.py", line 6, in a
print aa
NameError: global name 'aa' is not defined
the aa must be defined in the b function,
what can i do ,
thanks
aa is only defined in the scope of b(). You can pull the variable definition out of the function or use it as an argument.
This should work:
This should also work, of course: