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.
精彩评论