Create index.html
Browse files- index.html +48 -0
index.html
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.3/full/pyodide.js"></script>
|
5 |
+
<title>PyOnline ®</title>
|
6 |
+
</head>
|
7 |
+
|
8 |
+
<body>
|
9 |
+
<p>
|
10 |
+
You can execute any Python code. Just enter something in the box below and
|
11 |
+
click the button.
|
12 |
+
</p>
|
13 |
+
<input id="code" value="sum([1, 2, 3, 4, 5])" />
|
14 |
+
<button onclick="evaluatePython()">Run</button>
|
15 |
+
<br />
|
16 |
+
<br />
|
17 |
+
<div>Output:</div>
|
18 |
+
<textarea id="output" style="width: 100%;" rows="6" disabled></textarea>
|
19 |
+
|
20 |
+
<script>
|
21 |
+
const output = document.getElementById("output");
|
22 |
+
const code = document.getElementById("code");
|
23 |
+
|
24 |
+
function addToOutput(s) {
|
25 |
+
output.value += ">>>" + code.value + "\n" + s + "\n";
|
26 |
+
}
|
27 |
+
|
28 |
+
output.value = "Initializing PyOnline Runner...\n";
|
29 |
+
// init Pyodide
|
30 |
+
async function main() {
|
31 |
+
let pyodide = await loadPyodide();
|
32 |
+
output.value += "Ready!\n";
|
33 |
+
return pyodide;
|
34 |
+
}
|
35 |
+
let pyodideReadyPromise = main();
|
36 |
+
|
37 |
+
async function evaluatePython() {
|
38 |
+
let pyodide = await pyodideReadyPromise;
|
39 |
+
try {
|
40 |
+
let output = pyodide.runPython(code.value);
|
41 |
+
addToOutput(output);
|
42 |
+
} catch (err) {
|
43 |
+
addToOutput(err);
|
44 |
+
}
|
45 |
+
}
|
46 |
+
</script>
|
47 |
+
</body>
|
48 |
+
</html>
|