please consider the following code:
class A:
a = "a"
def print_a(self):
print("A says:", self.a)
def print_warning_a(self):
print("A says:", "Warning! B wrote something!")
class B:
b = "b"
def print_a(self):
print("B says:", self.b)
def print_warning_b(self):
print("B says:", "Warning! A wrote something!")
if __name__=="__main__":
class_a = A()
class_b = B()
class_a.print_a()
class_b.print_b()
I would like the output to be something like:
>> A says: a
>> B says: Warning! A wrote something!
>> B says: b
>> A says: Warning! B wrote something!
In other words: I have theese two classes (A and B). I would like to call a method of class A whenever another method of class B is called. Also, I would like to call a method of class B whenever another method of class A is called, assuming this would not cause an infinite loop (as in the example above).
In this case I would like to call print_warning_a() when print_b() of class B fires, and also I would like to call print_warning_b() when print_a() of class A fires.
How can I modify the code to achieve this?
Thank you.