我很新的python,目前正在玩zeroconf库。python这是什么数据类型?
当我尝试到网络上,我看到这个在函数定义上注册一个服务:
def register_service(self, info, ttl=_DNS_TTL):
"""Registers service information to the network with a default TTL
of 60 seconds. Zeroconf will then respond to requests for
information for that service. The name of the service may be
changed if needed to make it unique on the network."""
self.check_service(info)
self.services[info.name.lower()] = info
if info.type in self.servicetypes:
self.servicetypes[info.type] += 1
else:
self.servicetypes[info.type] = 1
now = current_time_millis()
next_time = now
i = 0
while i < 3:
if now < next_time:
self.wait(next_time - now)
now = current_time_millis()
continue
out = DNSOutgoing(_FLAGS_QR_RESPONSE | _FLAGS_AA)
out.add_answer_at_time(DNSPointer(info.type, _TYPE_PTR,
_CLASS_IN, ttl, info.name), 0)
out.add_answer_at_time(DNSService(info.name, _TYPE_SRV,
_CLASS_IN, ttl, info.priority, info.weight, info.port,
info.server), 0)
out.add_answer_at_time(DNSText(info.name, _TYPE_TXT, _CLASS_IN,
ttl, info.text), 0)
if info.address:
out.add_answer_at_time(DNSAddress(info.server, _TYPE_A,
_CLASS_IN, ttl, info.address), 0)
self.send(out)
i += 1
next_time += _REGISTER_TIME
任何人都知道什么类型的info
的意思是什么?
编辑
感谢提供,这是一个ServiceInfo
类的答案。除了文档字符串在人们搜索时提供这个答案的事实。我还是不明确的:
- 过程中遇到这种情况时,专家Python程序员遵循 - 文档字符串的时候没有采取什么措施来找到
info
数据类型说呢? - python解释器如何知道
info
是ServiceInfo类的,当我们没有指定类类型作为register_service
的输入参数的一部分?它如何知道info.type
是一个有效的属性,并且说info.my_property
不是?
你在哪里看到这个定义?我似乎无法找到'register_service'在https://github.com/wmcbrine/pyzeroconf – ryachza
我要添加'info .__ class__'到'register_service'函数,但我不能调用该函数作为' info'是一个输入参数。任何其他方式我可以调用该函数?如果我添加了'info = None',它会使数据类型失效吗? – snowbound
哎呀,对不起@ZJM。错误的链接。这是正确的:https://github.com/jstasiak/python-zeroconf – snowbound