Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Why python is faster than java?

0 Answers  


What does none mean in python?

0 Answers  


When to use list vs. tuple vs. dictionary vs. set?

1 Answers  


What are python decorators? 8) What is the difference ...

0 Answers  


What does ord () do in python?

0 Answers  


What are the attributes?

0 Answers  


Can constructor be private?

0 Answers  


How many functions are in python?

1 Answers  


How to find the index of an element in a list python?

0 Answers  


What is speech_recognition? Does this ship with python by default?

0 Answers  


What are the basic datatypes in python?

0 Answers  


What is the encapsulation?

0 Answers  


Categories