在Python中渲染Quarto文档时无法使用命令行中的参数值到Quarto文件

问题描述 投票:0回答:1

我尝试使用 quarto CLI 传递参数值,并在带有 Python 代码的 Quarto 文件中使用它,但它不起作用。

使用命令:

quarto render test.qmd -P foo:5 --output test_cmd_out.html

四开本文档 (

test.qmd
):

---
title: "Test File"
format: html
html:
embed-resources: true
execute:
  echo: False
jupyter: python3

---

# Title


Print this in report
```{python}
foo
```

---

错误:

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

我是否需要将其用作

params$foo
,即使对于 Python 或其他方式也是如此?

如果我查看他们的文档,不确定出了什么问题。

python jupyter command-line-arguments quarto
1个回答
0
投票

问题是如何在 Quarto 文档中调用参数值,从文档中我还不太清楚,但这对其他人也可能有帮助。

正确的做法是:

---
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)
```
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.