我正在设计一个过滤器设计图形用户界面,并希望在QTextBrowser中显示来自Python的QTextBrowser的文档字符串,这需要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_string对它在docstring中遇到的第一个标题(“参数”)进行了限制:
docutils.utils.SystemMessage: <string>:10: (SEVERE/4) Unexpected section title.
Parameters
----------我认为原因是该方法的整个docstring是缩进的,导致无效的reST标记。是否有一种简单的方法来减少文档字符串,或者告诉publish_string忽略一定数量的前导空格?
完整的代码可以在pyFDA项目上找到。
发布于 2015-02-24 10:20:23
您可以使用textwrap.dedent,如文档所述:
从文本中的每一行中删除任何常见的前导空格。
例如(来自关于CodeReview的一个类似问题):
>>> 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 deployhttps://stackoverflow.com/questions/28693002
复制相似问题