如何以键/值格式打印对象?

时间:2015-08-10 00:06:05

标签: python python-3.x dnspython

print()函数将下面的dns查询结果作为字符串输出,但我需要查看此结果的KEYS。我尝试使用pprint()getmembers()vars()dir(),但它们会输出许多不相关的属性,并且不会像{{1}那样直接显示结果功能确实:

print()

如何以对象格式(键/值对)获得等效的import dns req = dns.message.make_query('msn.com', dns.rdatatype.ANY) res = dns.query.udp(req, '8.8.8.8', timeout=3) print(res) =========================================================== OUTPUT (Command Prompt) =========================================================== id 12637 opcode QUERY rcode NOERROR flags QR RD RA ;QUESTION msn.com. IN ANY ;ANSWER msn.com. 685 IN A 23.101.196.141 msn.com. 21385 IN NS ns3.msft.net. msn.com. 21385 IN NS ns4.msft.net. msn.com. 21385 IN NS ns1.msft.net. msn.com. 21385 IN NS ns2.msft.net. msn.com. 21385 IN SOA ns1.msft.net. msnhst.microsoft.com. 2015080901 7200 900 2419200 900 msn.com. 685 IN MX 5 mx4.hotmail.com. msn.com. 685 IN MX 5 mx1.hotmail.com. msn.com. 685 IN MX 5 mx2.hotmail.com. msn.com. 685 IN MX 5 mx3.hotmail.com. msn.com. 685 IN TXT "v=spf1 include:Spf-a.hotmail.com include:Spf-b.hotmail.com include:Spf-c.hotmail.com include:Spf-d.hotmail.com include:_spf-ssg-a.microsoft.com include:Spf.protection.outlook.com ~all" ;AUTHORITY ;ADDITIONAL 函数结果?类似于JSON对象的样子,这可能吗?

0 个答案:

没有答案