2

I'd like to have a class that contains a function that is called whenever another class function is called. And the tricky part is that I'd like this to work for derived classes.

Let's say:

def class A:
  def __init__(self):
    pass
  def b(self):
    print("Hello")

and

def class B(A):
  def __special_method__(self):
    print("Before Hello")

And calling object.b() would print

Before Hello
Hello

Is this even possible?

FMAPR
  • 61
  • 5
  • 3
    Does this answer your question? [Catch "before/after function call" events for all functions in class](https://stackoverflow.com/questions/25828864/catch-before-after-function-call-events-for-all-functions-in-class) – Adam Kern May 05 '21 at 22:50
  • 1
    Oh damn thanks Adam! I think a decorator could help, yes. – FMAPR May 05 '21 at 23:27

0 Answers0