How to pass a global variable to a module?
Hendrik van Rooyen
hendrik at microcorp.co.za
Wed Sep 30 09:08:39 CEST 2009
On Tuesday, 29 September 2009 20:24:53 Mars creature wrote:
> >From the link Gregor posted, it seems no way to share variable between
> I can understand the point that global variables tends to mess up
> Assume that I have 10 parameters need to pass to the function. If
> these parameters are fixed, I can use another module to store these 10
> parameters, and import to the module, as suggested by jean-michel. But
> what if these 10 parameters will be changed in the main program?
> Passing the variable to the function as a parameter suggested by Rami
> will certainly do, but I am wondering weather there are other ways.
> What you'd like to code it?
You can put all the 10 things in a file called say my_params.py.
Then where you need it, you do either:
from my_params import * to make them available where needed,
import my_params as p and access them as:
More information about the Python-list