There is a function
def startInvRej(self, event): if 2 < event.button < 4: self.canvCoor = [] self.frameCoor = [] print(event.x) print(event.xdata) self.frameCoor.append(event.x) self.canvCoor.append(float(event.xdata)) print(self.frameCoor) print(self.canvCoor)
How to wrap it in a decorator so that the function is executed with debugging output (i.e. with print), if necessary, otherwise without it?
After your answers and brief thoughts, it was decided to do this:
def decorator(func): def wrapped(self, event): print(event.x) print(event.xdata) func(self, event) print(self.frameCoor) print(self.canvCoor) return wrapped @decorator def startInvRej(self, event): if event.button ==3: self.canvCoor = [] self.frameCoor = [] self.frameCoor.append(event.x) self.canvCoor.append(float(event.xdata))
How correct is this method? And explain, please, why this method works despite the fact that I wrote func(self, event)
, and not startInvRej(self, event)
?