How do we share global variables across modules in Python?



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

Post New Answer

More Python Interview Questions

What do you understand by monkey patching in python?

0 Answers  


How can files be deleted in python?

0 Answers  


What is the usage of dir() and dir() function in python?

0 Answers  


How do you sort in descending order in python?

0 Answers  


Is pypy faster than python?

0 Answers  






What is py checker in python?

0 Answers  


What does isalpha do in python?

0 Answers  


How to pass indefinite number of arguments to any function?

0 Answers  


What is *args and **kwargs?

0 Answers  


Can python be used for web client and web server side programming?

0 Answers  


What is standard output in python?

0 Answers  


What is the use of map in python?

0 Answers  


Categories