ObjectA calling ObjectB
Lawrence Oluyede
raims at dot.com
Sat Dec 27 15:42:05 EST 2003
MidasOneTwo at hotmail.nospam.com (Midas) writes:
> In my "main" code, I would like to create two
> new objects (ObjectA and ObjectB) and have
> ObjectA directly call an ObjectB method. In
> order to do this I believe ObjectA must hold
> a reference to ObjectB. What about the name
> of the method? Must it be hardcoded in
> ObjectA?
You could simply do something like this:
class A:
def __init__(self):
self.ObjectB = B()
class B:
def someMethod(self):
pass
if __name__ == "__main__":
ObjectA = A()
ObjectA.ObjectB.someMethod()
HTH
--
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com
More information about the Python-list
mailing list