Skip to content
Advertisement

Get globals() dict from other module

I have follow this method to create a settings file with globals.

settings.py I have :

JavaScript

in main.py :

JavaScript

I cannot see “test” in globals ! Any idea please ?

Advertisement

Answer

In Python, global variables are only global in the module where they were defined.

If you want to access the global variables of an imported module, you can use:

JavaScript

Or if you only want the public ones (not starting with a leading underscore):

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement