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(se lf):
self.objB=modul eB.MyClassB()
def validate(self,a ge,address):
if(age >= 100 or address==''):
self.age=20;
self.address="B roadway,NewYork "
self.objB.displ ay(self.age,sel f.address)
def callB(self):
self.objB.execu te()
if __name__ == "__main__":
objA=MyClassA()
objA.createClas sB()
objA.callB()
moduleB.py
------------------
import moduleA
class MyClassB:
def __init__(self):
self.createA()
def createA(self):
self.objA=modul eA.MyClassA()
def execute(self):
self.objA.valid ate(111,'')
def display(self,ag e,address):
print 'displaying:',s tr(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
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(se lf):
self.objB=modul eB.MyClassB()
def validate(self,a ge,address):
if(age >= 100 or address==''):
self.age=20;
self.address="B roadway,NewYork "
self.objB.displ ay(self.age,sel f.address)
def callB(self):
self.objB.execu te()
if __name__ == "__main__":
objA=MyClassA()
objA.createClas sB()
objA.callB()
moduleB.py
------------------
import moduleA
class MyClassB:
def __init__(self):
self.createA()
def createA(self):
self.objA=modul eA.MyClassA()
def execute(self):
self.objA.valid ate(111,'')
def display(self,ag e,address):
print 'displaying:',s tr(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
Comment