這篇文章主要介紹python查看對(duì)象屬性的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)整合營(yíng)銷推廣、網(wǎng)站重做改版、西秀網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為西秀等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
在Python語(yǔ)言中,有些庫(kù)在使用時(shí),在網(wǎng)絡(luò)上找到的文檔不全,這就需要查看相應(yīng)的Python對(duì)象是否包含需要的函數(shù)或常量。下面介紹
一下,如何查看Python對(duì)象中包含哪些屬性,如成員函數(shù)、變量等,其中這里的Python對(duì)象指的是類、模塊、實(shí)例等包含元素比較多的
對(duì)象。這里以O(shè)penCV2的Python包c(diǎn)v2為例,進(jìn)行說(shuō)明。
1. dir() 函數(shù)
dir([object]) 會(huì)返回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對(duì)象的__dict__屬性,其中object對(duì)象可以是模塊,類,實(shí)例,或任何其他有__dict__屬性的對(duì)象。所以,其與
直接訪問(wèn)__dict__屬性等價(jià)。示例如下(這里是反例,mser對(duì)象中沒(méi)有__dict__屬性):
>>> 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__'
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__ = <built-in method __new__ of type object> | T.__new__(S, ...) -> a new object with type S, a subtype of T
以上是python查看對(duì)象屬性的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
名稱欄目:python查看對(duì)象屬性的方法
URL鏈接:http://sd-ha.com/article32/gcjesc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、標(biāo)簽優(yōu)化、Google、云服務(wù)器、定制開發(fā)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)