How do we share global variables across modules in Python?
Answer Posted / 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 |
Post New Answer View All Answers
Is python call by reference or value?
How can you access a module written in python from c?
Why python is fast?
How does the ternary operator work in python?
Does pandas recognize dates when importing data?
What are the packages?
Why do you use abstract classes?
Is python client or server side?
What is unlink in python?
What is hello world in python?
Is geany good for python?
How to do relative imports in python?
What does do in python?
Is there any way to kill a thread in python?
What is docstring? How to define it?