开发者

In Sphinx documentation, is it possible to use the module name to specify a code sample to be included?

I'd like to 开发者_如何学编程include a code example in my sphinx documentation. I don't, however, want to refer to the file by its path, but would rather specify it by its module name.

That is, instead of doing it the way indicated here Showing code examples

.. literalinclude example.py

or

.. literalinclude ../../example.py

I'd rather do (for example)

.. includemodule mymodule.example

Is this possible to do without writing a custom extension? Or, what is the simplest way to write such an extension?


You can reference other classes by using something like this:

:class:`~module.submodule.Class`

If you add the examples as doctest to the class than you have examples which are guaranteed to work since they are directly runnable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜