Python
Sat Jan 11 2025

Content Extraction

In addition to snippets manipulation that is applicable to any language, Znai can extract content of methods.
:include-python: python/example.py {entry: "Animal.says", bodyOnly: true}
print("hello")
python/example.py
class Animal:
    """
    animal top level class doc string

    ```
    code block
    ```
    """

    def says(self):
        """
        animal **talks** `code`
        """
        print("hello")
Head over to Python Content Extraction to learn more

Description Extraction

Znai provides plugin to extract PyDoc content. Use it to extract high level description and merge it with the rest of the documentation. Convert method parameters into API Parameters
:include-python-doc-params: python/pydoc-params.py {entry: "my_func", title: "result and parameters"}
result and parameters
returns
status of the operation
OK for good
label
label to use to render item in the store
price
price associated with the item
python/pydoc-params.py
def my_func(label, price):
    """
    text inside my *func* doc
    * list one
    * list two

    Parameters
    ----------
    label : str
      label to use to *render* item in the store

    price : fin.money.Money
      price associated with the **item**

    Returns
    -------
    str
      status of the operation

      `OK` for good
    """

    return "OK"
Head over to Python Description Extraction to learn more

Auto Reference

Znai provides plugins to automatically create reference documentation for methods and classes.
:include-python-method: fin.money.render_money
fin.money
.
render_money
(
,
message
:
=
""
)
->
render money to a string
returns
money represented as text
amount to print
message
message to use for audit
fin/money.py
def render_money(amount: Money, message: str = "") -> str:
    """
    render money to a string

    Parameters
    --------------
    amount:
      amount to print

    message:
      message to use for audit

    Returns
    -------
      money represented as text
    """

    return f"{message} {amount.amount} {amount.currency}"
Head over to Python Auto Reference to learn more