文章詳情頁(yè)
Python2中code.co_kwonlyargcount的等效寫法
瀏覽:166日期:2022-06-30 13:19:32
問(wèn)題描述
假設(shè)有這樣一段代碼:
>>> def add (x,y):... return x + y... >>> c = add.__code__
對(duì)于Python3而言,我們可以通過(guò)c.co_kwonlyargcount獲取到其關(guān)鍵字參數(shù)為0,對(duì)于Python2而言,如何實(shí)現(xiàn)等效的寫法,獲取到其對(duì)應(yīng)的關(guān)鍵字參數(shù)的數(shù)量。
問(wèn)題解答
回答1:https://docs.python.org/2/lib...
回答2:python2和python3的參數(shù)數(shù)量獲取不一樣:
def add(x, y): return x + y python2:c = add.func_codec.co_argcountpython3:c = add.__code__c.co_argcount
上一條:python - tweepy 庫(kù) 連接Twitter API 報(bào)錯(cuò)下一條:python小白基礎(chǔ)問(wèn)題 關(guān)于while循環(huán)
相關(guān)文章:
1. vue.js - vue 打包后 nginx 服務(wù)端API請(qǐng)求跨域問(wèn)題無(wú)法解決。2. css3 - css如何實(shí)現(xiàn)素描描邊效果3. java - Mybatis關(guān)聯(lián)查詢4. docker綁定了nginx端口 外部訪問(wèn)不到5. PHP單例模式6. css - transform-origin 旋轉(zhuǎn)參考點(diǎn)7. javascript - ndoe 如何讀取mac系統(tǒng)下.numbers文件,或者解析.numbers文件的庫(kù)8. css3 - flex兩端布局9. javascript - 如何更改瀏覽器默認(rèn)字體大小10. html - 在一個(gè)table表單中 td用v-for 使用v-if判斷是否顯示 然后用一個(gè)外部的button 判斷點(diǎn)擊最后一行隱藏
排行榜

熱門標(biāo)簽