New to python and have situation like this:
myfun.py:
def fun(x, ...):
par1 = ...
par2 = ...
... # many pars
parn = ...
return #*long and complicated function of all the pars and x inputs*
Sometimes I'd like to modify one or more of the pars without modifying myfun.py itself. I know I could:
- Define every par as an argument to fun and give it a default value
- Make a dictionary par_dict = {'par1': ..., ...} then wherever I have par1 in my return code replace it with par_dict['par1']. Then use par_dict.update() to take a dictionary argument and update my pars.
Any clean and compact alternatives to these options? I'd like something like this:
fun(x_in, par10=5)
# output uses 5 where par10 occurs in the function, in other words the argument to the function overrides the values set inside the function.
Thank you.
*argsand/or**kwargsmay be useful.