I have 2 modules, each contains a class.
My main program instantiates an object of class One, which instantiates many objects of class Two.
I need to be able to call a function in class One from the instances of class Two.
This is a general look of what I have:
module mod_one.py:
import mod_two
class One:
def __init__(self):
self.new_instance = Two()
def call_back_func(self):
# This function should be called
# from the new instance of class Two()
module mod_two.py:
class Two:
def __init__(self):
# Call call_back_func() of module mod_one
The only way I found was to pass the callback function call_back_func() as an argument to class Two like so:
self.new_instance = Two(self.call_back_func)
but I'd like to know if there is a better way of doing that.