cannot find object instance

jimgardener jimgardener at gmail.com
Thu Aug 28 11:35:07 EDT 2008


hi,
i am a python newbie..while trying out some message passing between
two object instances i came across a problem
moduleA.py
--------------------
import moduleB
class MyClassA:
    def __init__(self):
        self.age=0
        self.address=''
    def createClassB(self):
        self.objB=moduleB.MyClassB()
    def validate(self,age,address):
        if(age >= 100 or address==''):
            self.age=20;
            self.address="Broadway,NewYork"
        self.objB.display(self.age,self.address)
    def callB(self):
        self.objB.execute()

if __name__ == "__main__":
    objA=MyClassA()
    objA.createClassB()
    objA.callB()

moduleB.py
------------------
import moduleA

class MyClassB:
    def __init__(self):
        self.createA()
    def createA(self):
        self.objA=moduleA.MyClassA()
    def execute(self):
        self.objA.validate(111,'')
    def display(self,age,address):
        print 'displaying:',str(age),address

when i run the code i get a message
AttributeError: MyClassA instance has no attribute 'objB'

Do i have to put a placeholder for objB in __init__ of MyClassA ?
is that why i get this error?someone please tell me how i can solve
this? I tried to put self.objB=None but it didn't work..(i was
thinking of java style objB=NULL )

please help
thanks
jim



More information about the Python-list mailing list