Namespace problem

Denis S. Otkidach ods at fep.ru
Tue May 28 05:56:30 EDT 2002


On Tue, 28 May 2002, Geiger Ho wrote:

GH> Hi all,
GH>
GH> Consider:
GH>
GH> File1.py:
GH> ---------
GH> import File2
GH> import File3
GH>
GH> class A:
GH>   def __init__(self):
GH>       self.b = File2.B()
GH>       self.c = File3.C()

          self.c = File3.C(weakref.proxy(self))

GH>   def run():
GH>       pass
GH>
GH> if __name__ == '__main__':
GH>   a = A()
GH>   a.run()
GH>
GH>
GH> File2.py:
GH> ---------
GH> class B:
GH>   def foo(self):
GH>       pass
GH>
GH> File3.py:
GH> ---------
GH> class C:

      def __init__(self, a):
          self.a = a

GH>   def fun(self):
GH>       # a method need to callback a.b.foo()
GH>       # how can I implement

          self.a.b.foo()

GH> Question:
GH> How should I call the a.b.foo() in the fun method?

C instance know nothing about a.  You should import a from
__main__ (I guess it's a bad idea) or initialize C with a.






More information about the Python-list mailing list