Python查看对象属性的方法
帮助https://docs.python.org/2/library/functions.html
dir() 函数
D:\pythontest>python
Python 3.5. (v3.5.0:374f501f4567, Sep , ::) [MSC v. bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> res = requests.get('https://www.sogou.com/link?url=DSOYnZeCC_popvGkrcLjd__A2
nuyEZQRtN0U1Xf4Goe7gAE91qpuJw..')
>>>
>>>
>>> dir(res)
['__attrs__', '__bool__', '__class__', '__delattr__', '__dict__', '__dir__', '__
doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribu
te__', '__getstate__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '
__lt__', '__module__', '__ne__', '__new__', '__nonzero__', '__reduce__', '__redu
ce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '_
_subclasshook__', '__weakref__', '_content', '_content_consumed', '_next', 'appa
rent_encoding', 'close', 'connection', 'content', 'cookies', 'elapsed', 'encodin
g', 'headers', 'history', 'is_permanent_redirect', 'is_redirect', 'iter_content'
, 'iter_lines', 'json', 'links', 'next', 'ok', 'raise_for_status', 'raw', 'reaso
n', 'request', 'status_code', 'text', 'url']
>>>
>>>
>>> print(res.url)
https://www.sogou.com/link?url=DSOYnZeCC_popvGkrcLjd__A2nuyEZQRtN0U1Xf4Goe7gAE91
qpuJw..
>>> print(res.text)
<meta content="always" name="referrer"><script>window.location.replace("http://w
ww.hujiang.com/ciku/register/")</script><noscript><META http-equiv="refresh" con
tent="0;URL='http://www.hujiang.com/ciku/register/'"></noscript>
help() 函数
调用内置帮助系统
>>> help(res)
Help on Response in module requests.models object: class Response(builtins.object)
| The :class:`Response <Response>` object, which contains a
| server's response to an HTTP request.
|
| Methods defined here:
|
| __bool__(self)
| Returns True if :attr:`status_code` is less than .
|
| This attribute checks if the status code of the response is between
| and to see if there was a client error or a server error. If
| the status code, is between and , this will return True. This
| is **not** a check to see if the response code is `` OK``.
|
| __enter__(self)
|
| __exit__(self, *args)
|
| __getstate__(self)
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
|
|
|
|
|
|
|
| -- More -- #按q退出
vars() 函数
vars([object]) 返回object对象的__dict__属性,其中object对象可以是模块,类,实例,或任何其他有__dict__属性的对象。所以,其与直接访问__dict__属性等价。示例如下(这里是反例,mser对象中没有__dict__属性):
>>> vars(res)
{'request': <PreparedRequest [GET]>, 'reason': 'OK', 'headers': {'Server': 'ngin
x', 'UUID': '6e3340cd-af97-40b4-bc43-f61aef2f27fc', 'Content-Type': 'text/html;
charset=GBK', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Expires':
'Sat, 24 Aug 2019 16:01:02 GMT', 'Content-Encoding': 'gzip', 'Date': 'Sat, 24 Au
g :: GMT', 'Set-Cookie': 'ABTEST=||v17; expires=Mon, -Se
p- :: GMT; path=/, IPLOC=CN4601; expires=Sun, -Aug- :: GMT; do
main=.sogou.com; path=/, SUID=E5FF1D6F2513910A000000005D615F3E; expires=Fri, -
Aug- :: GMT; domain=.sogou.com; path=/, black_passportid=; domain=.so
gou.com; path=/; expires=Thu, -Dec- :: GMT', 'Transfer-Encoding': 'c
hunked', 'P3P': 'CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE CO
M NAV OTC NOI DSP COR", CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA
PRE COM NAV OTC NOI DSP COR", CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT
DEM STA PRE COM NAV OTC NOI DSP COR"', 'Cache-Control': 'max-age=0'}, 'status_co
de': 200, '_content_consumed': True, 'history': [], 'elapsed': datetime.timedelt
a(, , ), '_content': b'<meta content="always" name="referrer"><script>wi
ndow.location.replace("http://www.hujiang.com/ciku/register/")</script><noscript
><META http-equiv="refresh" content="0;URL=\'http://www.hujiang.com/ciku/registe
r/\'"></noscript>', 'cookies': <RequestsCookieJar[Cookie(version=, name='IPLOC'
, value='CN4601', port=None, port_specified=False, domain='.sogou.com', domain_s
pecified=True, domain_initial_dot=True, path='/', path_specified=True, secure=Fa
lse, expires=, discard=False, comment=None, comment_url=None, rest={},
rfc2109=False), Cookie(version=, name='SUID', value='E5FF1D6F2513910A000000005
D615F3E', port=None, port_specified=False, domain='.sogou.com', domain_specified
=True, domain_initial_dot=True, path='/', path_specified=True, secure=False, exp
ires=, discard=False, comment=None, comment_url=None, rest={}, rfc2109
=False), Cookie(version=, name='ABTEST', value='0|1566662462|v17', port=None, p
ort_specified=False, domain='www.sogou.com', domain_specified=False, domain_init
ial_dot=False, path='/', path_specified=True, secure=False, expires=,
discard=False, comment=None, comment_url=None, rest={}, rfc2109=False)]>, 'url':
'https://www.sogou.com/link?url=DSOYnZeCC_popvGkrcLjd__A2nuyEZQRtN0U1Xf4Goe7gAE
91qpuJw..', '_next': None, 'encoding': 'GBK', 'raw': <urllib3.response.HTTPRespo
nse object at 0x00000000034BE9B0>, 'connection': <requests.adapters.HTTPAdapter
object at 0x00000000034AA4A8>}
>>>
type() 函数
type(object)返回对象object的类型。
>>> type(res)
<class 'requests.models.Response'>
callable() 函数
callable(object):若object对象是可调用的,则返回True,否则返回False。注意,即使返回True也可能调用失败,但返回False调用一定失败。
>>> callable(res)
False
Python查看对象属性的方法的更多相关文章
- getSelection、range 对象属性,方法理解,解释
网上转了一圈发现没有selection方面的解释,自己捣鼓下 以这段文字为例子.. <p><b>法国国营铁路公司(SNCF)20日承认,</b>新订购的2000列火 ...
- Javascript对象属性与方法汇总
Javascript对象属性与方法汇总 发布时间:2015-03-06 编辑:www.jquerycn.cn 详细介绍下,javascript对象属性与对象方法的相关知识,包括javascript字符 ...
- js object 对象 属性和方法的使用
//object 对象 属性和方法的使用 var person = new Object(); person.name="张海"; person.age="; perso ...
- 转: JavaScript 获取对象属性和方法
一.获取对象属性和方法 Object.keys()for in 返回对象的可枚举属性和方法的名称数组. Object.getOwnPropertyNames() 返回的数组的所有属性(可枚举或不可枚举 ...
- Js基础知识7-JavaScript所有内置对象属性和方法汇总
对象什么的,程序员可是有很多呢... JS三大对象 对象,是任何一个开发者都无法绕开和逃避的话题,她似乎有些深不可测,但如此伟大和巧妙的存在,一定值得你去摸索.发现.征服. 我们都知道,JavaScr ...
- ES6之6种遍历对象属性的方法
ES6之6种遍历对象属性的方法 for ... in 循环遍历对象自身的和继承的可枚举属性(不含Symbol属性). Obejct.keys(obj),返回一个数组,包括对象自身的(不含继承的)所有可 ...
- JavaScript 获取对象属性和方法
ShineJaie 原创整理,转载请注明出处. 一.获取对象属性和方法 Object.keys() 返回对象的可枚举属性和方法的名称数组. Object.getOwnPropertyNames() 返 ...
- JavaScript 访问对象属性和方法及区别
这篇文章主要介绍了浅析JavaScript访问对象属性和方法及区别的相关资料,仅供参考 属性是一个变量,用来表示一个对象的特征,如颜色.大小.重量等:方法是一个函数,用来表示对象的操作,如奔跑.呼吸. ...
- JS枚举对象属性的方法及其区别
愉快的中秋节要过去了,国庆倒计时两个周!!! 闲话不多说,那今天我们来看一看JS中枚举对象属性的方法有哪些以及他们的区别 首先在JS里面枚举对象属性一共有三种方法 for in: 会遍历对象中所有的可 ...
随机推荐
- Express post请求无法解析参数的原因
router.post('/', function(req, res) { console.log(req.body); console.log(req.body.name); console.log ...
- Oracle删除修改字段
Oracle 增加修改删除字段 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],…. ...
- 树的性质——cf1244D
特别简单,只有链的形式才符合要求,那么枚举前两个点的颜色搞一下就可以 #include <bits/stdc++.h> using namespace std; ][],pos[],ok= ...
- Linux中网卡配置/etc/sysconfig/network-script/ifcfg-eth0
网络接口配置文件 [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 TYPE=Ethernet #网卡类型 DEVIC ...
- delphi 调用js脚本
function ExecScript(Code,Lang,Func:string):string; var script:OleVariant; begin script:=CreateOleObj ...
- robotium学习
20140424 控件种类:spinner:下拉菜单,可以选择:TabHost:可以左右滑动,比如电话本:Gallery:rogressbar进度条;DatePicker;CheckBox,Radio ...
- H5项目(基于vue框架)常见问题及注意事项
参考: https://blog.csdn.net/u012377333/article/details/52326158 1.前端中所有的按钮,点击后发送报文的标签,都必须加上 去重功能.防止重复发 ...
- MySql精简
安装的是免安装版MySql 由于MySql是开源的,故下载的时候源码也会包含,如果单纯只是使用其功能,则可以将这些文件删除为MySql减肥 可以删除的文件有如下: 1.mysql-test 文件夹: ...
- (转)C#中String跟string的“区别”
string是c#中的类,String是.net Framework的类(在C# IDE中不会显示蓝色) C# string映射为.net Framework的String 如果用string,编译器 ...
- hibernate5.2.10.Final基本配置
1.在官网去下载,解压后在lib/required目录下的所有jar包都是必要的. 2.为了之后配置方便,建议在eclipse里面安装一个东东,操作步骤是在eclipse->Help->I ...