Say I have some very long function module.my_function that's something like this:
def my_function(param1,param2,param3='foo',param4='bar',param5=None,...)
With a large number of args and keyword args. I want this function to be usable both as a part of module module and as a class method for myClass. The code for the function will remain exactly the same, but in myClass a few keyword args may take different default values.
What's the best way of doing this? Previously I was doing something like:
class myCLass(object):
def __init__(self,...
def my_function(self, param1,param2,param3='hello',param4='qaz',param5=['baz'],...):
module.my_function(param1,param2,param3=param3,param4=param4,param5=param5,...)
It seems a little silly to write all these arguments that many times, especially with a very large number of arguments. I also considered doing something like module.my_function(**locals()) inside the class method, but I'm not sure how to handle the self argument and I don't know if this would lead to other issues.
I could just copy paste the entire code for the function, but that doesn't really seem very efficient, when all that's changing is a few default values and the code for my_function is very long. Any ideas?