Skip to content

[Q&A]: setup 'cell' behaviour in book project #17

Description

@lmoresi

What's your question?

Great plugin / extension. Really great start at making code snippets work for web documents. Installation of the current version of the extension

My question is related to the setup cell/s that I would like to use to install some files in the local filesystem so students can practice reading and writing simple files in python (before they get to more complicated packages to do this for them).

The simplest example is below. I define a variable in a setup cell, and try to reference it later.

If I change the first cell to run interactively, it works, of course. I am not sure how to debug (how to see if code in the setup is run but in the wrong namespace ?) or if this is simply not yet fully implemented. Is this my issue or should I raise this as a bug ?

---
title: Test Pyodide plugin
author: 
    - Louis Moresi
---

```{pyodide-python}
#| context: setup
x = 1
```

```{pyodide-python}
#| context: interactive
print(x)
```

Output of cell 2:

PythonError: Traceback (most recent call last):
  File "/lib/python311.zip/_pyodide/_base.py", line 573, in eval_code_async
    await CodeRunner(
  File "/lib/python311.zip/_pyodide/_base.py", line 393, in run_async
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "", line 1, in 
NameError: name 'x' is not defined

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions