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
What is a panda in python?
Mention five benefits of using python?
Which programming language is a good choice between java and python?
What is scheduling in threading?
What are the built-in type does python provides?
How do you split a list into evenly sized chunks in python?
Why do we want to use break statement in while-loop?
What are advantages of a tuple over a list?
Describe how to send email from a python script?
What is the difference between list and tuples?
Is python 0 indexed?
Why python language is called python?
What are object methods?
Who created the Python programming language?
Can we develop a web application using Python