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
Name few python checkers for debugging?
Please write a reg expression that confirms an email id using the python reg expression module
What is dict when we have to use ?
How python manage memory?
How can I force division to be floating point in python?
How do you dispose a variable in python?
How are the functions help() and dir() different?
What is a pass in python?
How to change a string in list ?
Is upper in python?
Explain how memcached should not be used in your python project?
Why cannot lambda forms in Python contain statements?
What is format () in python?
What is the output for the following code?
What is the output of this following statement?