Module question

Mikalai mbirukou at yahoo.com
Tue Feb 21 17:24:15 EST 2006


Tuvas wrote:
> I know this is probably a very simple question, but I am building a
> program that is now at about 2400 lines of code in the main module. I
> need to break it up, however, there are certain variables that I would
> like to use among all of them, namely the TKinter background. It's
> build using tkinter, so, to do anything useful requires having the
> master=Tk() variable portable in every interface. I can't just pass
> this variable, the real way to do it is to have a global variable. How
> can I do this? Thanks!

I will write an example with comments:

# say, this is a file/module foo
x = 1 # this is our variable
# end of module foo
----------------------
# other module, where x is needed
import foo
foo.x  # here you have it
# end
----------------------

It is all simple, but you need to have proper hierarchical import-ing.
You are splitting a file, which has a hierarchical order (count lines),
so writting proper importing is possible at least in principle.

Mikalai




More information about the Python-list mailing list