对类方法进行约束(类的抽象方法ABC+raise抛出异常 )

#base.py
#####方法一######
from abc import ABCMeta
from abc import abstractmethod class BaseMessage(metaclass=ABCMeta): @abstractmethod
def send(self,subject,body,to,name):
pass ########方法二#######
class BaseMessage(object):
def send(self, subject, body, to, name):
raise NotImplementedError('未实现send方法') #######dingding.py#########
from .base import BaseMessage class DingDing(BaseMessage):
def __init__(self):
pass def send(self,subject,body,to,name):
print('钉钉消息发送成功')
上一篇:Appium的环境搭建和配置


下一篇:2021年官网下载各个版本JDK最全版与官网查阅方法