Importing JS Objects in Python
In PyScript and Pyodide, the pseudo-module js
is a proxy for the JavaScript Global Scope. That is to say, if we have an variable in the JavaScript global scope:
<script>
// Create a JavaScript global variable called my_string
var my_string = "Hello, world"
</script>
We can access it (and in this case, print the string it represents) using either any of the following Python syntax options:
Using from js import *
does not work; however, you can get a list of all objects in the JavaScript global scope using: