日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python如何查看對象的屬性

在Python語言中,有些庫在使用時(shí),在網(wǎng)絡(luò)上找到的文檔不全,這就需要查看相應(yīng)的Python對象是否包含需要的函數(shù)或常量。下面介紹

一下,如何查看Python對象中包含哪些屬性,如成員函數(shù)、變量等,其中這里的Python對象指的是類、模塊、實(shí)例等包含元素比較多的

對象。這里以O(shè)penCV2的Python包c(diǎn)v2為例,進(jìn)行說明。

1. dir() 函數(shù)

 dir([object]) 會返回object所有有效的屬性列表。示例如下:

$ 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() 函數(shù)

vars([object]) 返回object對象的__dict__屬性,其中object對象可以是模塊,類,實(shí)例,或任何其他有__dict__屬性的對象。所以,其與

直接訪問__dict__屬性等價(jià)。示例如下(這里是反例,mser對象中沒有__dict__屬性):

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

3. help() 函數(shù)

help([object])調(diào)用內(nèi)置幫助系統(tǒng)。輸入

>>> help(mser)

顯示內(nèi)容,如下所示:

Help on MSER object:

class MSER(FeatureDetector)
 |  Method resolution order:
 |      MSER
 |      FeatureDetector
 |      Algorithm
 |      __builtin__.object
 |  
 |  Methods defined here:
 |  
 |  __repr__(...)
 |      x.__repr__() <==> repr(x)
 |  
 |  detect(...)
 |      detect(image[, mask]) -> msers
 |  
 |  ----------------------------------------------------------------------
 |  Data and other attributes defined here:
 |  
 |  __new__ = 
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T

更多技術(shù)請關(guān)注Python視頻教程。


當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:python如何查看對象的屬性
當(dāng)前網(wǎng)址:http://www.5511xx.com/article/djpggid.html