我有一个简单的 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_addition
和make 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/