python子类约束
class Foo(object):
def f1(self):
#父类的函数中加上一个raise
raise NotImplementedError
class New(Foo):
def f2(self):
#如果子类定义了一个父类中不存在的方法,则会报错
print('f1')
obj=New()
Traceback (most recent call last):
File "G:\py_project\api\app_api\tests.py", line 70, in <module>
obj.f1()
File "G:\py_project\api\app_api\tests.py", line 61, in f1
raise NotImplementedError
NotImplementedError