-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
011663d
commit cbe8660
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |