python what data type is this?
我是python的新手,目前正在使用zeroconf库。
当我尝试在网络上注册服务时,我在函数定义中看到了这一点:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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 |
有人知道
编辑
感谢您提供答案,它是一个
-
遇到这种情况时,流程专家python程序员会遵循-在没有文档字符串的情况下,要采取什么步骤查找
info 的数据类型? -
当我们不将类类型指定为
register_service 的输入参数的一部分时,python解释器如何知道info 是ServiceInfo类的? 如何知道info.type 是有效属性,而又说info.my_property 不是?
它是ServiceInfo类的实例。
可以通过阅读代码和文档字符串来推断。
看起来它应该是
https://github.com/jstasiak/python-zeroconf/blob/master/examples/registration.py
编辑
我更喜欢静态类型。在很大程度上,我认为使用动态类型时文档和单元测试只是"更严格的要求",因为编译器无法为您完成任何工作。