I have a bunch of functions, some of them require a bar parameter, some of them require a foo parameter, some of them require neither, and some require both.
I am hoping to call all of these functions from the same location, as the function is referenced from a variable.
The possible solutions I have found is:
- function(bar = "some_value", foo = "other value")
- Using inspect and then detecting which arguments need to be passed in
I don't believe #1 will work, but I know that #2 will. Is there a native (not using a library) way for me to do this?
As an example:
functions = [lambda foo: foo.do_something(),
lambda bar: bar.do_something_else(),
lambda foo, bar: foo.something_with_bar(bar),
lambda: do_another_task()
]
for function in functions:
//call goes here
Note: I actually have many, many functions that I want to call with these parameters, and they aren't all stored nicely in an array. I would prefer if I could do it without changing the functions themselves.
fooandbarmight not only be arguments to the function, but also instances from which you are referencing the function? That's a more complicated scenario...