I am trying to pass parameter value using quarto CLI and use it in Quarto file with Python code but it’s not working.
Command used:
quarto render test.qmd -P foo:5 --output test_cmd_out.html
Quarto doc (test.qmd
):
---
title: "Test File"
format: html
html:
embed-resources: true
execute:
echo: False
jupyter: python3
---
# Title
Print this in report
```{python}
foo
```
---
Error:
Starting python3 kernel...Done
Executing 'test.quarto_ipynb'
Cell 1/1: ''...ERROR:
An error occurred while executing the following cell:
------------------
foo
------------------
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[1], line 1
----> 1 foo
NameError: name 'foo' is not defined
Do I need to use it as params$foo
even for Python or some other way?
Not sure what is wrong if I look at their documentation.
The issue is how the parameter value is called in the Quarto document, it wasn’t really clear enough for me from the document but this may be helpful for others too.
Correct way to do that is:
---
title: "Test File"
format: html
embed-resources: true
execute:
echo: false
jupyter: python3
---
# Title
Print this in report
```{python}
#| tags: [parameters]
foo = "default"
```
```{python}
# Using the parameter
print(foo)
```