How does a user can share global variables across modules ?
How does a user can share global variables across modules ?
4 views
1 Answers
The canonical way to share information across modules within a single program is to create a special module (called config or cfg). Just import the config module in all modules of application. The module then becomes available as a global name. Because there is only one instance of each module, any change made to the module object get reflected everywhere. For example,
config. py:
x=0
mod.py:
import config
config.x=1
main.py :
import config
import mod
print config.x
4 views
Answered