引自:https://www.cnblogs.com/klchang/p/7296058.html
1. dir() 函数
dir([object]) 会返回一个包含object的所有状态的列表。示例如下:
class House:
area=200
floor=7
worth=700
location='上海松江'
print(dir(House))
'''结果
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__',sizeof__', '__str__', '__subclasshook__', '__weakref__', 'area', 'floor', 'location', 'worth']
vars([object]) 返回包含object对象的__dict__属性的字典,其中object对象可以是模块,类,实例,或任何其他有__dict__属性的对象。所以,其与直接访问__dict__属性等价。示例如下
class House:
area=200
floor=7
worth=700
location='上海松江'
print(House.__dict__)
'''
结果
{'__module__': '__main__', 'area': 200, 'floor': 7, 'worth': 700, 'location': '上海松江', '__dict__': <attribute '__dict__' of 'House' objects>, '__weakref__': <attribute '__weakref__' of 'House' objects>, '__doc__': None}
'''
3. help() 函数
help([object])调用内置帮助系统。
import requests
i=requests.Response
#print(dir(i))#查看类response的所有状态
print(help(i))#使用help函数,查看详细的response类,或者print(help(Response))