I am having a lot of different functions that are going to be operated on instances of a specific class, DSM
. I would like to have them working both as instance functions to the class, as well as separate functions on a module level. The functions are currently stored in two different modules, similarity.py
and compositions.py
, while the class is stored in model.py
.
As such, I could import the functions from each module and apply the functions on the class in a traditional manner, similarity.cos(dsm_instance, arg1, arg2)
, which is what I want. What I want as well is to have all functions in each module automatically added to the class instance, so I could call dsm_instance.cos(arg1, arg2)
.
Because the class instances take a lot of time to create I am caching each instance as soon as they are created. Because of this I would prefer if the functions from each module were added to the class instance in runtime. This is to be able to fix any bugs and add new functionality to each class instance without the need to recreate the instance itself.
To summarize: How do I automatically add all functions from specific modules in such a way that the functions are added in runtime and not when the instance first is created?