Python代碼實現Object文檔查看

來源:互聯網
上載者:User

標籤:cin   查看   輸出   and   除了   method   程式   顯示   div   

任務說明:

  1 利用Python代碼實現Object對象的文檔說明,除了使用help外;

  2 練習使用字串,Object預設方法等

  3 按照可選擇的格式顯示

程式說明

import requests‘‘‘擷取對象的調用函數和doc文檔的資訊object:需要擷取函數的對象spacing:規整方法名輸出顯示長度collapse:格式化方法名和doc文檔之間的輸出顯示        0:按照原文檔顯示        1:方法名和doc文檔之間用空格間隔‘‘‘def info(object, spacing=20, collapse=1):    methodList = [method for method in dir(object)     if callable(getattr(object,method))]    # 1 and "a" or "b"    # "a"    # 0 and "a" or "b"    # "b"    processFuc = collapse and (lambda s:" ".join(s.split())) or (lambda s:s)    print("\n".join(        ["%s %s"%(method.ljust(spacing), processFuc(str(getattr(object,method).__doc__)))         for method in methodList]))if __name__ == ‘__main__‘:    info(requests,collapse=0)

 

Python代碼實現Object文檔查看

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.