This global variable may not be defined. If this code is executed and the variable is undefined then a NameError will occur.

Check that the name of the global variable is not a typographic error. If the name is correct then define the variable or import the module that defines the function or method.

If it is expected this variable will be initialized from another module before it is used, then the NameError may not occur. Nonetheless, the code will be more robust and clearer if the variable is set to a default value in its own module.

The following examples show two different examples of undefined "global variables".

  • Python Standard Library: NameError.
  • The Python Tutorial: Modules.