Skip to main content
4 of 4
make it more clear where the exclamation point is coming from
maxywb
  • 2.6k
  • 2
  • 20
  • 26

A more concise example might be as follows:

#/usr/bin/env python3 from functools import wraps def wrapper(method): @wraps(method) def _impl(self, *method_args, **method_kwargs): method_output = method(self, *method_args, **method_kwargs) return method_output + "!" return _impl class Foo: @wrapper def bar(self, word): return word f = Foo() result = f.bar("kitty") print(result) 

Which will print:

kitty! 
maxywb
  • 2.6k
  • 2
  • 20
  • 26