Any variable globaldeclared inside the imported .py module remains global "inside" of its own module and is global "inside" the script or program where this module was imported (using Python import). Now, what if, after importing a module, Xdeclare a global variable Y. And I want to make the variable Y "visible" or globalfor functions defined in the imported module X(so I do not need to pass Yin the functions of the imported module as an argument)?
to import "myModule.py":
def printX():
print variableX
def printY():
global variableY
variableY='y'
print variableY
Main program
import myModule as myModule
myModule.printY()
print myModule.variableY
global variableX
variableX='X'
print variableX
myModule.printX()
myModule.printX() result:
NameError: global name 'variableX' is not defined