[Tutor] Package problems

Ismael Garrido ismaelgf at adinet.com.uy
Sun Feb 19 08:10:11 CET 2006


Hello.

I'm trying to make a package (so that later I can "import package"). I 
created one dir with an __init__.py, main.py, one.py

__init__.py :
from main import *

main.py :
import one

Now, main.py creates one instance of a class (and there can be only that 
one instance) and provides several general purpouse functions that 
direct that instance to do something. The problem comes with one.py, 
which contains especialized functions which must use that same instance 
main.py uses. I don't want to merge the two files (it would be too 
clumsy, I think).

I tried making the instance a global:
global a
a = In()
But that doesn't work, one.py can't access "a"

The only solution that comes to my mind is to create a function in 
one.py that would create a global, something like:
def init(instance):
    global a
    a = instance

and then call it after finishing the instanciation of the class. I don't 
think this is a good solution. Can anyone suggest a better idea?

Thanks for your time,
Ismael


More information about the Tutor mailing list