funcstr = textwrap.dedent(
    """def func(x, {p}):
    return x * 2*a + 4*b - 5*c
""")

def make_model(**kwargs):
    params = set(('a', 'b', 'c')).difference(list(kwargs.keys()))
exec(funcstr.format(p=','.join(params)), kwargs)
return kwargs['func']
func = make_model(a=3, b=1)
xdata = np.array([1, 3, 6, 8, 10])
ydata = np.array([0.91589774, 4.91589774, 10.91589774, 14.91589774, 
    18.91589774])
popt, pcov = optimize.curve_fit(func, xdata, ydata)
print(popt)
Dynamically define a function