-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
59 lines (45 loc) · 1.19 KB
/
Copy pathindex.html
File metadata and controls
59 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Python by Example</title>
<link rel="stylesheet" href="css/style.css">
<!-- Pyodide -->
<script src="https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"></script>
</head>
<body>
<h1>Python by Example</h1>
<p>Run Python directly in your browser.</p>
<textarea id="code" rows="10">
print("Hello from Python by Example")
</textarea>
<br><br>
<button id="run">Run Code</button>
<pre id="output">Loading Python…</pre>
<script>
(async () => {
const output = document.getElementById("output");
const runBtn = document.getElementById("run");
output.textContent = "Loading Python…";
const pyodide = await loadPyodide();
output.textContent = "Python ready. Click Run Code.";
runBtn.onclick = async () => {
output.textContent = "";
try {
pyodide.setStdout({
batched: (s) => output.textContent += s
});
pyodide.setStderr({
batched: (s) => output.textContent += s
});
await pyodide.runPythonAsync(
document.getElementById("code").value
);
} catch (err) {
output.textContent = err.toString();
}
};
})();
</script>
</body>
</html>