Python开发接口
Python本身不提供Interface的创建和使用
安装zope.interface
pip install zope.interface

interface_demo.py

代码:
from zope.interface import Interface
from zope.interface.declarations import implementer
#定义接口
class IHost(Interface):
def sayHello(self, host):
"""Say Hello to host"""
@implementer(IHost) #继承接口
class Host:
def sayHello(self, guest):
return "Hi %s:" % guest
if __name__ == '__main__':
host1 = Host()
hello = host1.sayHello('Jake')
print(hello)
我是杰克船长,专注测试领域,从事软件测试10年+,先后在1号店,IBM从事软件测试工作,希望能帮助更多想在测试领域有兴趣的朋友,若有兴趣,可以加我微信:xlyu2006,大家一起学习,相互帮组,相互进步!

浙公网安备 33010602011771号