Skip to content
Advertisement

Python: Using property get/set to run on sub-class function

I have a setup that looks something like this simplified setup:

JavaScript

I understand the use of @property to do a get – set setup for an attribute. But in this case, I’m trying to figure out how I can directly call the WorkerBee methods (there are more than 1 in my case….) that would also trigger MainClass.updated_WorkerBee()

JavaScript

Any help is appreciated!

Advertisement

Answer

You could add a reference to the main object to the bee, like a parent:

JavaScript

and then use it in your update methods within WorkerBee, to update main too:

JavaScript

To do that, pass the main to the bee when you create it:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement