Here is the problem, I have a class that I would like to define in python to be able to pass the buck onto another class so to speak when a function to the primary class is called. For example:
class Multi_Interface:
def __init__(self):
interfaces = [Interface("message A"), Interface("Message B")]
self.set_interface(0)
def set_interface(self, interface_index = 0):
current_interface = self.interfaces[interface_index]
# @todo: override the .operator to call the member of the current interface.
class Interface:
def __init__(self, message):
self.msg = message
def do_stuff(self, message="I am a parameter"):
print message + self.msg
mi = Multi_Interface()
mi.do_stuff(message="the internal message is: ")
mi.set_interface(1)
mi.do_stuff(message="the internal message is: ")
mi.do_stuff()
>>> the internal message is: mesage A
>>> the internal message is: mesage B
>>> I am a parameter: mesage B
Is there a way to overload this operator for a class? How would one overload this operator? I have an idea on how to get the method from the child object provided I can get a string in a method.