import error between 2 modules

jimgardener jimgardener at gmail.com
Wed Aug 27 12:38:33 CEST 2008


I am new to python,and am learning from the tutorials
i created 2 .py files like below and put the main in one of them

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()


is this kind of mutual import not allowed in python?
I am getting
"from workmodule import Worker
ImportError: cannot import name Worker"

any advice/pointers most welcome
thanks
jim



More information about the Python-list mailing list