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 的有啥好處
參考
python:面向對象程式設計之Zope.interface安裝使用