This is more curiosity than practical.
I have a library function that accepts a function and passes in a variable, but I want to also call that function with other arguments.
def libFunc(fn):
fn("passes in a useless value")
def foo(a, b):
print(f"i want to call this function using libFunc with args {a}, {b}")
# This works fine
num1, num2 = 5, 10
libFunc(lambda x, a=num1, b=num2 : foo(a, b))
# is there a way to avoid using a lambda function here, maybe using a named function?
# i.e. what is the equivalent named function of the above lambda function
def bar(uselessValue, a, b):
return foo(a, b)
# my attempt but I'm not sure how to deal with the first argument being unknown
# without using partial functions from libraries
libFunc( bar(uselessValue=???, a=num1, b=num2) )
def bar(uselessValue, a=num1, b=num2):and call it withlibFunc(bar)? Lambdas are nothing special, you can always replace them with named functions.