Python查看對(duì)象或者方法使用幫助的三板斧

python中每一個(gè)對(duì)象或者對(duì)象的方法都有可以使用三種方式查看相關(guān)的使用方法和幫助文檔。

class SampleClass(object):
    """Summary of class here.

    Longer class information....
    Longer class information....

    Attributes:
        likes_spam: A boolean indicating if we like SPAM or not.
        eggs: An integer count of the eggs we have laid.
    """

    def __init__(self, likes_spam=False):
        """Inits SampleClass with blah."""
        self.likes_spam = likes_spam
        self.eggs = 0

    def public_method(self):
        """Performs operation blah."""


if __name__ == '__main__':
    
    # a = '5'  # xxxxx
    print(SampleClass.__doc__)
    print(dir(SampleClass))

    print(help(SampleClass))

    print(dir(SampleClass.public_method))
    print(help(SampleClass.public_method))

直接調(diào)用對(duì)象或者方法的doc屬性,或者使用dir()或者使用help()來(lái)查看就可以了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容