The module (tq84_mod.py)
The module has one function,
func()
, which assigns a value (
assigned in module's func()
) to a global
variable. This variable is global within the module, not within the entire execution.
def func():
global var
var = "assigned in module's func()"
The script
The script imports the module, assigns a value to var
calls func()
in the module and then prints the module's and the script's value of var
.
def func():
global var
var = "assigned in module's func()"
Because the script's (global) var
variable is another variable than the module's global var
variable, the script, when executed, prints:
var = assigned in script
tq84_mod.var = assigned in module's func()