I have an ensemble of functions: func1, func2, func3, ... funcN. Only 1 function will be used based on the user input, e.g. if user put '1', only func1 will be used. So far what I did is to put these function in a branch:
class FunctionEnsembles:
def __init__(self,select_funcion):
self.function_to_select=select_function
def function_to_use(self):
if self.function_to_select=='1':
func1...
elif self.function_to_select=='2':
func2...
...
Apparently this is not efficient. When the class gets instantiated, e.g FunctionEnsemble myfunc('1')
, the definition all the functions are involved. If one calls myfunc.function_to_use, it will go through all the branches, which is not desirable. What I want to do is :
function is selected once the class FunctionEnsemble
is instantiated, while unwanted functions are not touched.
How to effectively achieve this ? Many thanks.