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 does range () do in python?
What are the 3 types of relation?
Is sorted in python?
Write a sample program in enumerate()function in python?
What is the function of “self”?
Which is the fastest implementation of python?
Finally, tell us about bitwise operators in python?
Tell us something about python iterators.
Why is python weakly typed?
Do you know what is lambda in python?
Does python support interfaces like java does?
How do you write a range in python?