user_func is a function with either 1 or 2 parameters.
What's the best way to call the function with 2 parameters if it supports it, or call it with 1 parameter if not?
Here is one way I found..
What's the best way to call the function with 2 parameters if it supports it, or call it with 1 parameter if not?
Here is one way I found..
1 2 3 4 5 6 7 8 9 10 11 12 |
def caller(user_func): # user_func has either 1 or 2 parameters information = 'some information' extra_information = 'some other information' if user_func.__code__.co_argcount = = 2 : # if function has 2 parameters user_func(information, extra_information) else : # function has 1 parameter user_func(information) |