Python global variable scoping

Globals in Python are only global to their module. There are no names that you can modify that are global to the entire process.

You can accomplish what you want with this:

globals.py:

value = 0
def default():
    global value
    value = 1

main.py:

import globals
def main():
    globals.default()
    print globals.value

if __name__ == "__main__":
    main()

I have no idea whether a global like this is the best way to solve your problem, though.

Leave a Comment