I need to understand how I can access the variable that was passed to the function in the decorator.
Let me explain with an example, is it possible to do something like this:
class test(object):
....
@DecoratorClass(myWrapper(self, x))
def myFunction(self, x):
print x
print self.y
At some point an instance of the test-class is created, and myFunction is called from somewhere. I need to path the same argument to myWrapper.
I hope that this is clear enough.
The decorator replaces the function with a callable that wraps it, so the callable will be passed the same parameters as the original function. So, for example:
Note that you will need to delay construction of “myWrapper” until the function is executed (because you will not have the function parameter until then).