python 獲得函式說明的方法

2021-06-26 22:59:32 字數 933 閱讀 8488

dir()函式可以列出模組的內容

>>> import string

>>> dir(string)

['formatter', 'template', '_templatemetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapl', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']

列印文件的內容,print 類名.__doc__

class a:

"ssss"

sss只是對類的說明,沒有任何意義,print 類名.__doc__就是顯示的這個部分

呼叫pydoc進行訪問

函式說明python函式巢狀筆記 函式說明

ps 今天上午,非常鬱悶,有很多簡單基礎的問題搞得我有些迷茫,哎,幾天不寫就忘。目前又不當coo,還是得用心記 哦!關於函式內嵌函式作用域的條記 def test i 0defa print locals a printi test 這段,locals 的值為空,說明內嵌的a函式沒有認默引入i de...

python 函式星號引數說明

python中函式引數的傳遞是通過賦值來傳遞的。函式引數的使用又有倆個方面值得注意 先看第乙個問題,在python中函式引數的定義主要有四種方式 1.f arg1,arg2,這 是最常見的定義方式,乙個函式可以定義任意個引數,每個引數間用逗號分割,用這種方式定義的函式在呼叫的的時候也必須在函式名後的...

CFile Open函式說明

1 nopenflags cfile modecreate 建立乙個新的檔案,如果檔案存在將檔案擷取成長度為0。cfile modenotruncate 此標誌總是與modecreate 配合使用,如果檔案存在,不將檔案擷取成長度為0 如果檔案不存在即建立新檔案。這個功能往往很好用,比如說,當你需要...