I have the following situation: I have a single master_function
that I wish to pass a sub_function
into. The function that I wish to pass into this changes (for example 1 and 2). The arguments of each function also vary in their number and type.
def sub_function_1( x, y, z):
return x + y + z
def sub_function_2( x, y ):
return x + y
def master_function( x, y, z, F ):
return x*y + F()
Quick fix
The simple fix to this would be to write the function callback with all possible arguments, whether they are used or not:
def master_function( x, y, z, F ):
return x*y + F(x,y,z)
Then we can call master_function( x, y, z, sub_function_1)
or master_function( x, y, z, sub_function_2)
as desired.
Unfortunately, I have many functions that I wish to pass into the master function; so this approach is not suitable!
Is there a way to write F
in master_function
without reference to the arguments required? How can I generalise this?