Importing into 'containers' namespace

Steve Holden sholden at holdenweb.com
Thu Jan 4 07:53:40 EST 2001


Nikolai Kirsebom <nikolai.kirsebom at siemens.no> wrote in message
news:3a544e22.1199160471 at news.mch.sni.de...
> 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.
>
Passing it as an argument to the object initialiation is the usual way to
go, see below.

> 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
>
Change this so that the FrameWork is passed to the initializer:

class B:
    def __init__(self, F)
    self.b = F.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()
Change this to pass the FrameWork in to the object creation:

Sub = B.B(FrameWork)

> print Sub.b    # Produces '1' as output
>
> # ----------------------------------------------------------
>
> Thanks for any help.
> Nikolai
>
Hope this helps.

regards
 Steve







More information about the Python-list mailing list