在Sphinx文档中,是否可以使用模块名称来指定要包含的代码示例?
我想在我的 sphinx 文档中包含一个代码示例。 但是,我不想通过文件的路径来引用该文件, 但宁愿通过其模块名称来指定它。
也就是说,不要按照此处指示的方式显示代码示例
.. literalinclude example.py
或者
.. literalinclude ../../example.py
我宁愿do(例如)
.. includemodule mymodule.example
是否可以在不编写自定义扩展的情况下完成此操作? 或者,编写此类扩展的最简单方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用如下方式引用其他类:
如果您将示例作为 doctest 添加到类中,那么您将拥有保证可以工作的示例,因为它们可以直接运行。
You can reference other classes by using something like this:
If you add the examples as doctest to the class than you have examples which are guaranteed to work since they are directly runnable.