1.

How does a user can share global variables across modules ?

Answer»

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



Discussion

No Comment Found