约束类必须定义 一些方法
# 类的约束
import abc
class BaseHandler(metaclass=abc.ABCMeta):
# 约束必须实现handler
@abc.abstractmethod
def handler(self):
print('talk')
class China(BaseHandler):
def handler(self):
pass
p = China()
更缓和一点,调用时 没有定义会报错
class BaseHandler():
def handler(self):
raise NotImplementedError('handler must be Implemented')
def cmd(self):
raise NotImplementedError('cmd must be Implemented')
原文:https://www.cnblogs.com/Hybb/p/11973297.html