interaction between modules... globals?
Hans Nowak
ivnowa at hvision.nl
Wed Jul 7 08:59:27 EDT 1999
On 7 Jul 99, Gerrit Holl wrote:
> Hello,
>
> I have a program which consists of several little modules, but I encounter a
> problem with that. I have one module which returns a class instance, with
> messages as members, either Dutch or English. Every module needs that instance,
> but I don't want to pass it as an argument to every little function, the
> modules should find out theirselves. But I _also_ don't want to make that
> instance 5 times.
>
> So I thougt: I need a sort of global between the modules. Is this possible?
Why not use it like this:
[module mymodule.py]
class MyClass:
# blah blah
myinstance = MyClass()
Now we have the module with your much-used instance. This can be used
by other modules as follows:
[module a.py]
import mymodule
mymodule.myinstance.do_something(x,y)
But maybe you tried this approach already?
Hans Nowak (ivnowa at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
More information about the Python-list
mailing list