美文网首页数据分析师的日常我们就爱程序媛
Python查看对象或者方法使用帮助的三板斧

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

作者: 采菊东篱下 | 来源:发表于2017-09-01 17:57 被阅读130次

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()来查看就可以了。

相关文章

网友评论

    本文标题:Python查看对象或者方法使用帮助的三板斧

    本文链接:https://www.haomeiwen.com/subject/wpykjxtx.html