文字" *"在RestructuredText中

时间:2015-05-26 09:23:12

标签: python python-sphinx restructuredtext

我正在看这段代码:

def ook(*args):
    """Some silly function.

    :param *args: Optional arguments.
    """
    ...

一旦我运行Sphinx,我就会得到这么有用的错误:

WARNING: Inline literal start-string without end-string.

所以,我尝试param ``*``argsparam :literal:'*' args并仍然收到警告。

我如何拥有文字' *'在restructuredText?

2 个答案:

答案 0 :(得分:12)

您可以使用(有点难看)反斜杠引用:\*

编辑:作为一个(有点难看)的附录,如果您担心反斜杠的pylint警告,可以在字符串文字r中添加r""" ... docstring ... """。这在this pylint issue中被描述。

让不同的文本处理系统很好地共同破坏有时会破坏美学。

答案 1 :(得分:-1)

在restructuredtext中,您可以使用.. code :: python指令。

http://docutils.sourceforge.net/docs/ref/rst/directives.html#code

这允许你创建一个python代码的文字块而不会有任何丑陋的' \'字符。

看起来像这样:

.. code:: python

    def ook(*args):
        """Some silly function.

        :param *args: Optional arguments.
        """
        ...

使用您的函数的示例如下:

http://rst.ninjs.org/?n=c8ad07eaea190745755a6d80d37786e6&theme=basic