Support for python code execution inside a documentation #2835
petrhrobar
started this conversation in
General
Replies: 1 comment 10 replies
-
Take a look at Markdown Exec (I'm the author). It should be possible to use the extension in docstrings code blocks as well, given you are using mkdocstrings to inject them in your pages, though I did not test that. Example: def func(name: str, age: int):
"""
This function prints your name and age.
```python exec="yes" source="tabbed-left"
from module import func # you still have to import it :/
print(func("Thomas", 15))
```
"""
return f"hey {name} who is {age}." The UPDATE: updated the example. |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there currently a feature that allows to source some python function and output the function's output?
Suppose I have a function:
Now docstring provides an example and it would be rendered. However, the function example is kind of "hardcoded" when I change the function and not the docstring, the example output does not change as it is static.
Would it be possible to also some e.g.:
.. execute_code::
from src.example import func
func("Petr", 101)
This would always change the output as the function is being executed.
I have been looking at sphinx feature HERE
Beta Was this translation helpful? Give feedback.
All reactions