Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用docutils将scipy文档字符串(reST)转换为HTML_Python_Html_Restructuredtext_Docstring_Docutils - Fatal编程技术网

Python 使用docutils将scipy文档字符串(reST)转换为HTML

Python 使用docutils将scipy文档字符串(reST)转换为HTML,python,html,restructuredtext,docstring,docutils,Python,Html,Restructuredtext,Docstring,Docutils,我正在设计一个过滤器设计GUI,希望在QTextBrowser中显示Python的scipy.signal中的docstring,需要HTML格式。我认为docutils应该为我做这项工作,我试过了 from docutils.core import publish_string from scipy.signal import remez self.txtFiltInfoBox.append(publish_string(remez.__doc__, writer_name

我正在设计一个过滤器设计GUI,希望在QTextBrowser中显示Python的scipy.signal中的docstring,需要HTML格式。我认为docutils应该为我做这项工作,我试过了

from docutils.core import publish_string
from scipy.signal import remez
self.txtFiltInfoBox.append(publish_string(remez.__doc__,
          writer_name='html'))
其中txtFiltInfoBox是QTextBrowser实例。但是,publish_字符串会阻塞它在docstring中遇到的第一个标题(“参数”):

docutils.utils.SystemMessage: <string>:10: (SEVERE/4) Unexpected section title.

Parameters
----------
docutils.utils.SystemMessage::10:(严重/4)意外的节标题。
参数
----------
我认为原因是该方法的整个docstring缩进,导致reST标记无效。有没有一种简单的方法来删除docstring或告诉publish_string忽略一定数量的前导空格

完整的代码可以在中找到。

您可以使用,如文档所述:

删除文本中每一行的任何常见前导空格

例如(来自):


谢谢-太棒了!还有一个我不知道的Python模块。。。对不起,我没有足够的声誉来投票支持你。
>>> import textwrap
>>> print(textwrap.dedent(
        """
        Usage examples:
        Test deployment:
            $ fab [noinput] test deploy
        Staging deployment:
            $ fab [noinput] staging deploy
        Production deployment:
            $ fab [noinput] production deploy
        """
))

Usage examples:
Test deployment:
    $ fab [noinput] test deploy
Staging deployment:
    $ fab [noinput] staging deploy
Production deployment:
    $ fab [noinput] production deploy