If a function needs to modify a variable declared in global scope, it need to use the global declaration. However, if the function just needs to read a global variable it ca
Look at this code:
from module import function
def foo(x):
return function(x)
The name function
here is a global. It would get awfully tedious if I had to say global function
to get this code to work.
Before you say that your X
and my function
are different (because one is a variable and the other is an imported function), remember that all names in Python are treated the same: when used, their value is looked up in the scope hierarchy. If you needed global X
then you'd need global function
. Ick.