-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyodide button demo (SOF-6821) #132
base: dev
Are you sure you want to change the base?
Conversation
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) |
}); | ||
const dict = await this.pyodide.globals.toJs(); | ||
console.log("dict:", dict); | ||
console.log("RESULT:", result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@VsevolodX we need result.toJs()
to convert python dictionary into JS map. Then we can use .get(key)
to extract values. Note result
holds only functional return from python code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically this means we can only get the result of one run of code (the return of the last called function to be exact). A bit limiting, but in this particular usage, it's sufficient.
Looks like
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 |
No description provided.