Python编程:zope.interface实现接口
【摘要】 pypi : https://pypi.org/project/zope.interface/ 文档:https://zopeinterface.readthedocs.io/en/latest/index.html
面向对象中接口负责定义规则,具体实现类来实现规则
安装
pip install zope.interface
1
代码示例
from zope...
pypi : https://pypi.org/project/zope.interface/
文档:https://zopeinterface.readthedocs.io/en/latest/index.html
面向对象中接口负责定义规则,具体实现类来实现规则
安装
pip install zope.interface
代码示例
from zope.interface import Interface
from zope.interface.declarations import implementer
class IHuman(Interface): def say_hello(self): """这个文字没有会报错"""
@implementer(IHuman)
class Man(object): def say_hello(self): print("hello")
if __name__ == '__main__': man = Man() man.say_hello() # hello
so: 暂时没发现 zope.interface 的有啥好处
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/84586985
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)