Global variables in multiples functions in Python -


i try explain situation examples:

im using global declare variable work in function, when try sub function doesnt work.

register.py

def main():     alprint = input("enter something: ")     if alprint == "a":         def alcheck():             global checkdot             checkdot = input("enter opinion: ")         def altest():             global checktest             checktest = input("hope works: ")         alcheck()         altest() main() 

and content.py

from register import checktest  if checktest == "ad":     print("you welcome!") 

when declare variable checktest in sub function(function, altest()) of main, using global , importing file, doesnt work, tried lot of things, nothing.

it would work, except if user enters other a first input, checktest not defined, gives importerror. might want try instead:

def main():     global checktest, checkdot     def alcheck():         global checkdot         checkdot = input("enter opinion: ")     def altest():         global checktest         checktest = input("hope works: ")     alprint = input("enter something: ")     if alprint == "a":         alcheck()         altest()     else:         checktest = none         checkdot = none main() 

this way, checktest, , checkdot defined.


Comments