I have a function that I call from a module. Inside the function, the two variables that I am trying to get become global. When I run the module in IDLE on its own, I can access the variables after the function completes, as expected. When I call a function in the code into which I imported the module, I cannot access the variables.
Exit when I run it myself.
>>> globaltest() What is your name? tom What is your age? 16 >>> name 'tom' >>> age 16
And the code into which to import it.
import name_age name_age.globaltest()
but when I start an attempt to access the variables in the code where I imported it.
What is your name? tom What is your age? 16 >>> name Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> name NameError: name 'name' is not defined >>>
How to make a global variable in the code where I imported the module, or to access the variables "name" or "age" in this function.
source share