我很新的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