💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**sphinx比较适合为Python生成文档** 1.安装sphinx ```shell pip install sphinx sphinx-autobuild sphinx_rtd_theme ``` 2.python文件的注释 可以注释如下: ```python def Method(param1, param2): """ This is a reST style. :param param1: this is a first param :param param2: this is a second param :returns: this is a description of what is returned :raises keyError: raises an exception """ ``` rst的API文档关键字: ``` param, parameter, arg, argument, key, keyword: Description of a parameter. type: Type of a parameter. Creates a link if possible. raises, raise, except, exception: That (and when) a specific exception is raised. var, ivar, cvar: Description of a variable. vartype: Type of a variable. Creates a link if possible. returns, return: Description of the return value. rtype: Return type. Creates a link if possible. ``` 3.生成API文档 1. 在代码文件夹中建立:docs文件夹 2. 在docs文件夹运行`sphinx-quickstart`, 在之后的选项中autodoc设为y 3. 编辑`conf.py`. ```python import os import sys sys.path.insert(0, os.path.abspath('../')) #设置根目录 import sphinx_rtd_theme html_theme = 'sphinx_rtd_theme' html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] ``` 4. 运行`sphinx-apidoc -o ./ ../` 5. `make html` 6. 在_build中会有生成的html文件