ObjectA calling ObjectB

Midas MidasOneTwo at hotmail.nospam.com
Sat Dec 27 22:37:07 CET 2003


Thanks for replying.
It looks like you hardcoded the name ObjectB within ClassA. I'd like to avoid all hardcoding of names. In other words, I'd like ObjectA to be *told*, at run time, which object to call and which method to call.

On Sat, 27 Dec 2003 21:42:05 +0100, Lawrence Oluyede wrote:

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




More information about the Python-list mailing list