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..
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)