From 4042db26158c5c78cc8be6313927c29e5bba9181 Mon Sep 17 00:00:00 2001 From: Cyrille Bogaert Date: Thu, 28 Oct 2021 04:18:58 +0200 Subject: [PATCH] Added "globals" as a 2nd param to runPythonAsync (#1914) --- src/js/api.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/api.js b/src/js/api.js index df62d14d6..0903ebc8d 100644 --- a/src/js/api.js +++ b/src/js/api.js @@ -176,11 +176,14 @@ export async function loadPackagesFromImports( * console.log(result); // 79 * * @param {string} code Python code to evaluate + * @param {PyProxy} globals An optional Python dictionary to use as the globals. + * Defaults to :any:`pyodide.globals`. Uses the Python API + * :any:`pyodide.eval_code_async` to evaluate the code. * @returns {Py2JsResult} The result of the Python code translated to JavaScript. * @async */ -export async function runPythonAsync(code) { - let coroutine = Module.pyodide_py.eval_code_async(code, Module.globals); +export async function runPythonAsync(code, globals = Module.globals) { + let coroutine = Module.pyodide_py.eval_code_async(code, globals); try { return await coroutine; } finally {