Importing into 'containers' namespace

Nikolai Kirsebom nikolai.kirsebom at siemens.no
Thu Jan 4 05:24:25 EST 2001


There is probably an easy solution to this, but I can't seem to find
out.

I would like to make an object (instance) created in the 'importing'
namespace available in the imported module.

Example below:

# -----------------------------------------------------------
# File: B.py (the imported module)
# when loaded, the object 'FrameWork' is in the scope
class B:
    def __init__(self):
        self.b = FrameWork.a

# -----------------------------------------------------------
# File: A.py (the importer)

class A:
    def __init__(self):
        self.a = 1

# Create framework instanse
FrameWork = A()

# SOME IMPORT STATEMENT for module B
??

Sub = B.B()
print Sub.b    # Produces '1' as output

# ----------------------------------------------------------

Thanks for any help.
Nikolai




More information about the Python-list mailing list