0

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

settings.py I have :

def init()
    global test
    test = True

in main.py :

import settings
settings.init()
print(globals())

I cannot see "test" in globals ! Any idea please ?

acnguy
  • 5
  • 3

1 Answers1

0

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:

settings_globals = vars(settings)

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

settings_publics = {k: v for k,v in vars(settings).items if not k.startswith('_')}
Serge Ballesta
  • 121,548
  • 10
  • 94
  • 199