Global variables in multiples functions in Python
Question: i will try to explain my situation with examples:

Im using global to declare a variable but this work only in a function, when i
try to another sub function doesnt work.

register.py

    
    
    def main():
        alprint = input("Enter something: ")
        if alprint == "a":
            def alCheck():
                global CheckDot
                CheckDot = input("Enter your opinion: ")
            def alTest():
                global CheckTest
                CheckTest = input("Hope it works: ")
            alCheck()
            alTest()
    main()
    

and content.py

    
    
    from register import CheckTest
    
    if CheckTest == "ad":
        print("You are welcome!")
    

When i declare this variable checkTest in a sub function(function, alTest())
of main, using global and importing to another file, it doesnt work, i tried a
lot of things, but nothing.


Answer: It _would_ work, except that if the user enters something other than `a` for
the first `input`, `CheckTest` is not defined, so it gives an `ImportError`.
You might want to try something like this instead:

    
    
    def main():
        global CheckTest, CheckDot
        def alCheck():
            global CheckDot
            CheckDot = input("Enter your opinion: ")
        def alTest():
            global CheckTest
            CheckTest = input("Hope it works: ")
        alprint = input("Enter something: ")
        if alprint == "a":
            alCheck()
            alTest()
        else:
            CheckTest = None
            CheckDot = None
    main()
    

This way, `CheckTest`, and `CheckDot` are always defined.

