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 is os module?

0 Answers  


Can you list down some of the pdb commands for debugging python programs?

0 Answers  


Is python is a case sensitive?

0 Answers  


How memcached should not be used in your python project?

0 Answers  


What is reuests module will do?

0 Answers  






Explain the //, %, and ** operators in python?

0 Answers  


What are your weaknesses examples?

0 Answers  


Can python replace bash?

0 Answers  


What does the ‘yield’ keyword do?

0 Answers  


What is super () in react?

0 Answers  


What is long in python?

0 Answers  


Do you need python to run a python program?

0 Answers  


Categories