I need to understand how to solve the Name Error 'not defined'. So I made a code example below.
I have to files in the root directory, one must be used as a module. The first file is main and the second file is additional which I need to use as a module. So I have to move a function name greet() from the main to additional together with the global variable.
When I move the function from main to additional I have to import additional to main. The error that I get is global variable is not recognized. How do I import a module in such a way that I avoid the 'not accessed' or 'not defined' error message.
THIS IS main file before moving the greet function.
#global name = 'Leo' def greet(): global name print(f'Hello {name}!') greet() def do(): global name print(f'How is your day {name}?') do() THIS IS additional with the code taken from main
#global name = 'Leo' def greet(): global name print(f'Hello {name}!') greet() THE main should now be like this
def do(): global name print(f'How is your day {name}?') do()