How do we share global variables across modules in Python?
Answer / chaitanya
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 I want a, b & c to share between modules.
config.py :
a=0
b=0
c=0
module1.py:
import config
config.a = 1
config.b =2
config.c=3
print “ a, b & resp. are : “ , config.a, config.b, config.c
------------------------------------------------------------------------
output of module1.py will be
1 2 3
| Is This Answer Correct ? | 0 Yes | 0 No |
Is python written in c?
List out the different types of inheritance available in python?
Is vs in python?
Is anaconda the same as python?
Do lists start at 0 or 1?
What does none type mean in python?
What is the use of map in python?
Write a program to produce fibonacci series in python.
What is yield in python?
How do you alphabetize a list in python?
What is the syntax for dictionary comprehension in python?
Which database is used in python?