python - Sphinx自动函数生成不带换行符的python文档字符串

标签 python python-sphinx

我有一个简单的 python 包,其中包含 1 个模块,其中包含以下函数:

def sample_addition(num1=1, num2=2):
    """adding 2 numbers as an example

    this function will add 2 numbers in case of failre it will raise an exception
    @param num1: first number
    @type num1: float
    @param num2: second number
    @type num2: float
    @return: addition result
    @rtype: float
    """
    return num1 + num2

当使用.. autofunction::sample_additionmake html时,结果是:

general.sample_addition(num1=1, num2=2)
adding 2 numbers as an example

this function will add 2 numbers in case of failre it will raise an exception @param num1: first number @type num1: float @param num2: second number @type num2: float @return: addition result @rtype: float

我已在 conf.py -> 扩展 中安装并使用了 sphinx_epytext,但它无助于正确转换和显示 Epytext

问题:

我怎样才能让它看到文档字符串中的新行?

最佳答案

就像 markdown 和 rst 一样,它需要换行符来分隔不同的段落,您需要在 this function...@param ... 之间添加换行符,如下所示:

def sample_addition(num1=1, num2=2):
    """adding 2 numbers as an example

    this function will add 2 numbers in case of failre it will raise an exception

    @param num1: first number
    @type num1: float
    @param num2: second number
    @type num2: float
    @return: addition result
    @rtype: float
    """

return num1 + num2

关于python - Sphinx自动函数生成不带换行符的python文档字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29971141/

相关文章:

python - 如何更改代码来读取和创建多个 xml 文件?

python - Django-rest-framework @detail_route 用于特定网址

Python setuptools 读取 setup.cfg 配置时出现 AttributeError

python - 始终重新生成包含特定指令的 Sphinx 文档

python - 当模块需要在导入前设置时使用 sphinx 记录 sqlalchemy 类

python - 如何使用 Pyglet 播放音频(在生成器循环中)?

python - 在flask的celery文档中,为什么celery任务需要名称?

matlab - Mathworks 生成 Matlab HTML 文档的方法是什么?

python-sphinx - 是否可以在 ReST 文字 block 中插入超链接?

python - docs.python.org 是否使用 sphinx.ext.autodoc?