Open VsevolodX opened 1 year ago
Looks like globals
behave differently when we try to move data both ways. It does work any one way. If we do not pass any globals with runPythonAsync
, pyodide.globals.toJs().get(key)
does work. But do we really need it to both ways? I guess we have other options:
args
, do not call any functions there. Then access function names in JS via globals and call with args
pyodide.runPython(`
def sq(x):
return x * x
`);
const sq = pyodide.globals.toJs().get("sq");
console.log(sq(5));
Note that whenever there is python dictionary, we need .toJs()
to transform into JS map
.
The main problem is that when reading globals from pyodide instance, we get only default ones. Like name, loader etc, but not the ones that we added in python. Although the data is present inside pyodide and can be printed from python to the console (stdout)