Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a python parameter inline in a Quarto Markdown paragraph?

Tags:

quarto

I want to access a python parameter inside a standard Markdown paragraph. Think dynamically updated values in a text report. I don't want to do an f-string inside a code block outside the paragraph.

E.g. "... After [code1] years, we found [code2] instances of XYZ occurrences..."

A more detailed example of the expected behavior is in this RMarkdown Documentation.

I tried the RMarkdown syntax `python var_name` where var_name is a float and variations on that syntax with no success. Quarto is treating it like a code-formatted text block (not evaluating the code).

How do I do this in a Quarto .qmd file running the Jupyter Kernel in VS Code?

Edit:

Partial workarounds here (what I'm using now) and here. The first option requires string formatting for rounded floats, because float formatting leaves trailing zeros for some reason. I couldn't find documentation to make the second option more extendible.

like image 339
David M Vermillion Avatar asked Oct 21 '25 11:10

David M Vermillion


1 Answers

Inline code is now available starting Quarto version 1.4
https://quarto.org/docs/computations/inline-code.html

You will need to use brackets for specifying the programming language: `{python} var_name`

From the documentation:

```{python}
radius = 5
```

The radius of the circle is `{python} radius`

Will result in

The radius of the circle is 5

like image 162
ehudk Avatar answered Oct 24 '25 17:10

ehudk