创新互联Python教程:python如何看变量属性

python中查看变量属性的

我们是2013年至今的成都网站建设公司,提供网站建设,电商网站设计开发,外贸网站建设,响应式网页设计,微信小程序定制开发、等服务。为客户创造有价值的品牌营销体验,让互联网提升企业的竞争力!

1、使用dir()函数查看

dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。

$ python

Python 2.7.8 (default, Sep 24 2015, 18:26:19)

[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import cv2

>>> mser = cv2.MSER()

>>> dir(mser)

['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'detect', 'empty', 'getAlgorithm', 'getBool', 'getDouble', 'getInt', 'getMat', 'getMatVector', 'getParams', 'getString', 'paramHelp', 'paramType', 'setAlgorithm', 'setBool', 'setDouble', 'setInt', 'setMat', 'setMatVector', 'setString']

2、使用vars()函数查看

vars() 函数返回对象object的属性和属性值的字典对象。

>>> vars(mser)

Traceback (most recent call last):

File "", line 1, in 

TypeError: vars() argument must have __dict__ attribute

>>> mser.__dict__

Traceback (most recent call last):

File "", line 1, in 

AttributeError: 'cv2.MSER' object has no attribute '__dict__'

网页名称:创新互联Python教程:python如何看变量属性
URL网址:http://www.hantingmc.com/qtweb/news44/530894.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联