0

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.

1 Answer 1

0

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)
```
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.