Creating Python Function With Partial Parameters
I want to pass a Python function to another function with some of its parameters 'filled out' ahead of time. This is simplification what I am doing: def add(x, y): return x + y
Solution 1:
This is called currying, or partial application. You can use the built-in functools.partial(). Something like the following would do what you want.
import functools
def add(x,y):
return x + y
inc2 = functools.partial(add, 2)
print inc2(3)
Post a Comment for "Creating Python Function With Partial Parameters"