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 is means by string python?
How does Python’s list.sort work at a high level? Is it stable? What’s the runtime?
How do I know my python version?
Consider multiple inheritances here. Suppose class c inherits from classes a and b as class c(a,b). Classes a and b both have their own versions of method func(). If we call func() from an object of class c, which version gets invoked?
Narrate the difference between python arrays and lists.
Describe about the libraries of python?
Is there a tool to help find bugs or perform static analysis?
What are Python modules? Name a few Python built-in modules that are often used.
Can a constructor be final?
Give one example for multiple statements in single statement?
Is python a high level language?
What is python coded in?