How Will You Share Global Variables Across Modules?


If you add a variable to the <__builtin__> module, it will be accessible as if a global from any other module that includes <__builtin__> — which is all of them, by default. contains
print foo contains
import __builtin__ = 1
import a
The result is that "1" is printed.

Note: Python 3 introduced the builtins keyword as a replacement for the <__builtin__>.


© 2017