Le Wednesday 27 August 2008 12:38:33 jimgardener, vous avez écrit : > empmodule.py > ---------- > from workmodule import Worker > > class Employer: > def __init__(self,n): > self.name=n > self.worker=Worker() > def getemployerName(self): > return self.name > def callWorker(self,message): > self.worker.answerCall(message) > if __name__ == "__main__": > emp=Employer() > emp.callWorker("report to work") > > > workmodule.py > ------------------ > from empmodule import Employer > class Worker: > def __init__(self): > self.emp=Employer() > def answerCall(self,msg): > print "Worker :"+msg+" received > from :"+self.emp.getemployerName()
For this case you could do your import directly in the __init__ func and watch the infinite loop you did in action ! empmodule.py ---------- from workmodule import Worker class Employer: def __init__(self,n): self.name=n self.worker=Worker(self) def getemployerName(self): return self.name def callWorker(self,message): self.worker.answerCall(message) if __name__ == "__main__": emp=Employer() emp.callWorker("report to work") workmodule.py ------------------ class Worker: def __init__(self, employer): from empmodule import Employer if not isinstance(employer, Employer): raise ValueError("Not an employer") self.emp=employer() -- _____________ Maric Michaud -- http://mail.python.org/mailman/listinfo/python-list