ObjectA calling ObjectB

Lawrence Oluyede raims at dot.com
Sat Dec 27 21:42:05 CET 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):

if __name__ == "__main__":
  ObjectA = A()


Lawrence "Rhymes" Oluyede

More information about the Python-list mailing list