【问题标题】:How can I add an external Python file to my restructured text document?如何将外部 Python 文件添加到我的重组文本文档中?
【发布时间】:2013-09-14 12:21:45
【问题描述】:

我想用 Sphinx 和重组文本写一本书。作为大部分内容 将是用Python编写的解决方案我想将文本和代码分开。

是否有将外部 python 脚本添加到我的重组文本文档的命令?

我尝试使用

.. code-block:: python
    .. include:: unittest_exp1.py

.. code-block:: python
    .. file:: unittest_exp1.py

【问题讨论】:

    标签: python python-sphinx restructuredtext


    【解决方案1】:

    使用如 Sphinx 文档中所示的 literalinclude。

    .. literalinclude:: example.py
       :language: python
       :emphasize-lines: 12,15-18
       :linenos:
    

    【讨论】:

      【解决方案2】:

      你试过.. literalinclude:: filename吗?

      这里有一点example

      .. literalinclude:: filename
          :linenos:
          :language: python
          :lines: 1, 7-8 
          :start-after: 12
          :end-before: 5
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-27
        相关资源
        最近更新 更多