MENU
Question -

How do we share global variables across modules in Python?



Answer -

We can create a config file & store the entire global variable to be shared across modules or script in it. By simply importing config, the entire global variable defined. It will be available for use in other modules.
For example we want a, b & c to share between modules.
config.py :
a = 0
b = 0
c = 0
modulel.py:
import config
config.a = 1
config.b = 2
config.c = 3
• print ” a, b & c are : ” , config.a, config.b, config.c

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×