classParentClass: defnie_func(self): # 要求子类中必须实现该方法,否则在子类实例中不能调用该方法 raise NotImplementedError("parent class nie methods not implemented")
classChildClass(ParentClass): pass
cc = ChildClass() cc.nie_func()
结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) /tmp/ipykernel_46111/872110974.py in <module> 9 10 cc = ChildClass() ---> 11 cc.nie_func()
/tmp/ipykernel_46111/872110974.py in nie_func(self) 1classParentClass: 2defnie_func(self): # 要求子类中必须实现该方法,否则在子类实例中不能调用该方法 ----> 3raise NotImplementedError("parent class nie methods not implemented") 4 5
NotImplementedError: parent classnie methods not implemented