python在中,如何给自己编写的库添加help

2025-05-01 15:18:18
推荐回答(1个)
回答1:

使用module, class, method 的 docstring. help会自动识别这些docstring。


比如:

#!/usr/bin/env python2
# coding=utf-8

"""This is module help.

"""

class C1(object):
    """class's help string.

    """
    def __init__(self, a):
        """method's help string.

        """
        pass


def f1():
    """this is f1's help string.

    """
    pass

然后你可以import这个模块之后,使用 help(f1) 等查看docstring.