How to pass a global variable to a module?

Rami Chowdhury rami.chowdhury at
Tue Sep 29 18:49:10 CEST 2009

On Tue, 29 Sep 2009 09:40:29 -0700, Mars creature <jinbow at> wrote:

> Dear Python users,
>   I just start to use python and love this language. I met this
> problem when I try to save my functions in a separate file.
> The question is how I can pass a global variable to a function which
> is saved in another file. If I save the function I defined in the same
> file with the main program, there is no problem after I declare the
> global variable. But problem comes out when I save all the function is
> a separate file. Help is very much appreciated! Thanks!
> Jinbo

In Python, as in many other languages, I'd advise that you think about  
whether your variable needs to be global, or whether you could (or should)  
simply pass the variable to the function as a parameter.


Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)

More information about the Python-list mailing list