Python编程zope.interface实现接口

网友投稿 630 2022-05-30

pypi : https://pypi.org/project/zope.interface/

文档:https://zopeinterface.readthedocs.io/en/latest/index.html

面向对象中接口负责定义规则,具体实现类来实现规则

安装

pip install zope.interface

1

Python编程: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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

so: 暂时没发现 zope.interface 的有啥好处

参考

python:面向对象编程之Zope.interface安装使用

Python

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Numpy 库的安装
下一篇:Cloudify — 安装部署与基础使用
相关文章