Skip to main content

Environmental Variables

You can check to see if the variable is in the dictionaries returned by globals() and locals().

For a local variable:

if locals().get('abc'):
print(abc)

For a global variable:

if globals().get('abc'):
print(abc)

For an environment variable:

if os.environ.get('abc')=='True':
#abc is set to True