Suppose there are many methods in my class and I want to apply my decorator to each of them, later, when I add new methods, I want to apply the same decorator, but I donβt want to write @mydecorator over the time method declaration?
If I __call__ in __call__ , is this the right way?
IMPORTANT: the example below seems to solve a problem other than the original question.
EDIT: I would like to show this path, which is a similar solution to my problem for anyone who does not find this question later using a mixin, as mentioned in the comments.
class WrapinMixin(object): def __call__(self, hey, you, *args): print 'entering', hey, you, repr(args) try: ret = getattr(self, hey)(you, *args) return ret except: ret = str(e) raise finally: print 'leaving', hey, repr(ret)
Then you can in another
class Wrapmymethodsaround(WrapinMixin): def __call__: return super(Wrapmymethodsaround, self).__call__(hey, you, *args)
python decorator wrapper
rapadura Jun 10 2018-11-11T00: 00Z
source share