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 |
What are domains and tuples?
What is the dictionary in Python?
Which one is easier r or python?
How to check the string consists of alphanumeric characters ?
What is use of list comprehension ?
What is lambda in python 3?
How can you explicitly free memory in python?
What does while 1 mean in python?
Is python better than java?
What are all the operating system that python can run on?
What are tuples in python?
Tell me what is the difference between list and tuple?