following code. When I import this module and want to access value returned by func_B , it gives "nothing" instead of "something"
Though func_A was called before func_B, it should have changed the value of global variable var right?
var = "nothing"
def func_A(arg):
global var
#do something with arg
var = "something"
return var
def func_B():
return var
Yes, what's the problem?
so you created a variable, globalised it in the function and then changed it? why didn’t it work? Also you assigned the variable outside the function at the beginning; so shouldn’t it already be global and thus not need ‘var global’?
Обсуждают сегодня