I am trying to introduce some automation to a script I'm writing, and I'm having some trouble with calling a function that has parameters from another module. Here's the scenario:
I have two modules: test.py and Strategies.py. I have code that generates a list of all the functions in Strategies.py. From that list, I am using getattr to execute each function.
What I'm having problems with is that some of my functions have parameters. I am getting the following error with a function that has an 'x' argument:
TypeError: buy_test_function() missing 1 required positional argument: 'x'
To make this as clear as possible, here's the relevant code:
call_method = strategy_names[0][y]
call_method = getattr(Strategies, call_method)()
I know the first line above is working fine. I also know that it's the empty parentheses at the end of the second line that's causing the problem. The magic I need is finding a way to dynamically read each function's required arguments and execute the function with the necessary arguments in the parentheses.
I've tried to use inspect.signature(), but it keeps telling me the object is not callable.
I have to believe Python has an elegant solution to this, but I've had little luck on Google. Any assistance is greatly appreciated.
Thank you!