Skip to content

Commit

Permalink
Create pyodide07.html
Browse files Browse the repository at this point in the history
  • Loading branch information
hpssjellis authored Nov 1, 2023
1 parent 011663d commit cbe8660
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions public/convert/pyodide07.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

<script src="https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>

You can execute any Python code. Just enter some python code in the variable myPython resave this file to your own Github. <br>


<input type=button value = run onclick = "evaluatePython()"> <br>

<div id="output" >...</div>

<script>
const myOutput = document.getElementById("output");
const myPython = `
sum([1, 2, 3, 4, 5])
` // end all python code

function addToOutput(myResult) {
myOutput.innerHTML += "<br> >>>" + myPython + "<br>" + myResult + "<br>";
}

myOutput.innerHTML = "Initializing...<br>";
// init Pyodide
async function main() {
let pyodide = await loadPyodide();
output.value += "Ready!\n";
return pyodide;
}
let pyodideReadyPromise = main();

async function evaluatePython() {
let pyodide = await pyodideReadyPromise;
try {
let myReturn = pyodide.runPython(myPython);
addToOutput(myReturn);
} catch (err) {
addToOutput(err);
}
}
</script>
</body>
</html>

0 comments on commit cbe8660

Please sign in to comment.