Namespace problem

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue May 28 06:16:56 EDT 2002


Geiger Ho <s997659 at ee.cuhk.edu.hk> wrote in 
news:Pine.GSO.4.05.10205281716320.11422-100000 at sparc41:

> Hi all,
> 
> Consider:
> 
> File1.py:
> ---------
> import File2
> import File3
> 
> class A:
>   def __init__(self):
>       self.b = File2.B()
        self.c = File3.C(self)
>   def run():
>       pass
> 
> if __name__ == '__main__':
>   a = A()
>   a.run()
> 
> 
> File2.py:
> ---------
> class B:
>   def foo(self):
>       pass
> 
> File3.py:
> ---------
> class C:
    def __init__(self, a):
        self.a = a
>   def fun(self):
>       # a method need to callback a.b.foo()
>       # how can I implement
        self.a.b.foo()
> 
> Question:
> How should I call the a.b.foo() in the fun method?
One way to do this is shown above.

N.B. This creates a circular reference so don't expect the objects to be 
cleaned up immediately you have finished with them.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list