global variable defined in main script can't be accessed by a function defined in a different module
问题 I want to define a few variables in my main python script and use them in a function which is defined in a separate module. Here is an example code. Lets say the main script is named main.py and the module is called mod.py. Mod.py def fun(): print a main.py from mod import * global a a=3 fun() Now, this code gives me an error NameError: global name 'a' is not defined Can anyone please explain why the error is generated (i mean, a variable defined as global should be available to all functions