Is there a way to write a function that takes some parameter, to modify multiple existing functions? For example, if I have: def add(a, b): return a + b def minus(a, b): return a - b def offset_b(func, n): (??) func(a, b - n)  then I want to execute below: offset_b(add(1, 2), 0.5) offset_b(minus(1, 2), 0.5)  I know one way to do it is: def new_b(b): return b-0.5 add(1, new_b(b)) minus(1, new_b(b))  Is there a way to use a wrapper or something to take the func (add/minus) and n, so that every time if I input some add(1, 2) it actually does add(1, 2 - 0.5) instead of the original version?
Define a function that accepts an existing function with known parameters, and returns a new function that wraps it: import functools # To borrow wrapped function's docs nicely def offset_b(func, n): @functools.wraps(func) def wrapped(a, b): return func(a, b-n) return wrapped  You can then define new versions of add and minus that apply the offset: add_with_offset_1 = offset_b(add, 1) minus_with_offset_1 = offset_b(minus, 1)  Or if you want to be able to make a proper decorator to apply this mutation to a new function that should only be called with an offset applied, you can increase the nesting, to produce a decorator with parameters, so that the first call takes the offset and returns a function that, when called with another function, produces the wrapped function: def offset_b(n): def do_wrap(func): @functools.wraps(func) def wrapped(a, b): return func(a, b-n) return wrapped return do_wrap  which allows you to use it as before, but in a different ordering: offset_by_1 = offset_b(1) add_with_offset_1 = offset_by_one(add) # Or as one-liner: add_with_offset_1 = offset_b(1)(add) minus_with_offset_1 = offset_by_one(minus)  or use it as a decorator to modify the wrapped function immediately: @offset_b(0.5) def add(a, b): return a + b @offset_b(0.5) def minus(a, b): return a - b  so add and minus exist immediately with the offset of 0.5 applied to all calls (confusing in this case, but useful in others).