Python編程:zope.interface實(shí)現(xiàn)接口
pypi : https://pypi.org/project/zope.interface/
文檔:https://zopeinterface.readthedocs.io/en/latest/index.html
面向?qū)ο笾薪涌谪?fù)責(zé)定義規(guī)則,具體實(shí)現(xiàn)類來(lái)實(shí)現(xiàn)規(guī)則
安裝
pip install zope.interface
1
代碼示例
from zope.interface import Interface from zope.interface.declarations import implementer class IHuman(Interface): def say_hello(self): """這個(gè)文字沒(méi)有會(huì)報(bào)錯(cuò)""" @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: 暫時(shí)沒(méi)發(fā)現(xiàn) zope.interface 的有啥好處
參考
python:面向?qū)ο缶幊讨甖ope.interface安裝使用
Python
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。