最佳答案
当我的类被子类化时,有没有触发代码的方法?
class SuperClass:
def triggered_routine(subclass):
print("was subclassed by " + subclass.__name__)
magically_register_triggered_routine()
print("foo")
class SubClass0(SuperClass):
pass
print("bar")
class SubClass1(SuperClass):
print("test")
应该能输出
foo
was subclassed by SubClass0
bar
test
was subclassed by SubClass1