How to use a decorator to send arguments to a function in python

Viewed 869

I have a set of functions in python that gets the same 2 parameters + other parameters.

def myMethodA (param1, param2, specificParm)
    do code

 def myMethodB (param1, param2, specificParm1 specificParam2)
    do code

I waned to create a decorator that replace the need to call with the first 2 parameters by pushing the parameters before calling the function:

@withParams()
def myMethodA (specificParam)
        do code

But if I omit the parameters then the decorator can't call it either and if I leave them then the caller need to specify them as well.

anyway to solve this? Can I do something with args* but still have named parameters for specificParam? Also, How can I reference param1 and param2 inside myMethodA

4 Answers
Related