• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python如何看变量属性

python 搞java代码 3年前 (2022-05-21) 36次浏览 已收录 0个评论

python中查看变量属性的

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']

www#gaodaima.com来源gaodai$ma#com搞$代*码*网搞代码

2、使用vars()函数查看

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

>>> vars(mser)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: vars() argument must have __dict__ attribute

>>> mser.__dict__

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

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

更多Python知识请关注云海天Python教程栏目。

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python如何看变量属性

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址