免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3223 | 回复: 0
打印 上一主题 下一主题

使用help方法查看模块所拥有的方法和类的信息应该如何来理解? [复制链接]

论坛徽章:
5
程序设计版块每日发帖之星
日期:2016-04-15 06:20:00每日论坛发贴之星
日期:2016-04-15 06:20:0015-16赛季CBA联赛之八一
日期:2016-07-08 09:20:28操作系统版块每日发帖之星
日期:2016-08-03 06:20:002016科比退役纪念章
日期:2016-10-30 13:59:12
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-07-03 17:28 |只看该作者 |倒序浏览
本帖最后由 274920831 于 2018-07-03 18:04 编辑

根据这个链接:
https://blog.csdn.net/IMW_MG/article/details/78147764
中的这一段:

①A记录
关于A记录的实例代码如下:

# -*- coding: utf-8 -*-# @Time : 2017/10/1 9:58
# @File : DNS.py
# @Software: PyCharm
import dns.resolver
domain = input("请输入域名地址:")       # 输入域名地址
A = dns.resolver.query(domain, 'A')     # 指定查询记录为A型   
for i in A.response.answer:             # 通过response.answer方法获取查询回应信息   
# print(i)             
    for j in i.items:                  
        print(j)


这里的dns.resolver是一个模块,我根据help>dns.resolver,可以查到这个模块的类和相应的方法,例如它的query方法

我想确认下response.answer是否是dns.resolver的方法,查得如下的信息:

    class Answer(__builtin__.object)

     |  DNS stub resolver answer

     |  

     |  Instances of this class bundle up the result of a successful DNS

     |  resolution.

     |  

     |  For convenience, the answer object implements much of the sequence

     |  protocol, forwarding to its rrset.  E.g. "for a in answer" is

     |  equivalent to "for a in answer.rrset", "answer" is equivalent

     |  to "answer.rrset", and "answer[i:j]" is equivalent to

     |  "answer.rrset[i:j]".

     |  

     |  Note that CNAMEs or DNAMEs in the response may mean that answer

     |  node's name might not be the query name.

     |  

     |  @ivar qname: The query name

     |  @type qname: dns.name.Name object

     |  @ivar rdtype: The query type

     |  @type rdtype: int

     |  @ivar rdclass: The query class

     |  @type rdclass: int

     |  @ivar response: The response message

     |  @type response: dns.message.Message object

     |  @ivar rrset: The answer

     |  @type rrset: dns.rrset.RRset object

     |  @ivar expiration: The time when the answer expires

     |  @type expiration: float (seconds since the epoch)

     |  @ivar canonical_name: The canonical name of the query name

     |  @type canonical_name: dns.name.Name object

第一个问题:

这里的红色的Answer是一个类,那么下面的@ivar response和@type response是代表什么意思?如何来判断response.answer是一个方法?

第二个问题:

A = dns.resolver.query(domain, 'A')   

这里的A是一个对像吗?依据我的理解:

对像 = 模块.类()

而这里的格式是 :

A = 模块.方法(参数) ,那么这样的格式也可以生成对像吗?


第三个问题:

A = dns.resolver.query(domain, 'A')

如果这里的A是一个对像,按照这行的意思:

for i in A.response.answer:

A 做为一个对像,还是可以继续使用dns.resolver的方法response.answer,可以这样理解吗?




您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP