Python查看对象或者方法使用帮助的三板斧

python中每一个对象或者对象的方法都有可以使用三种方式查看相关的使用方法和帮助文档。

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))

直接调用对象或者方法的doc属性,或者使用dir()或者使用help()来查看就可以了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容