-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
34 lines (31 loc) · 995 Bytes
/
index.html
File metadata and controls
34 lines (31 loc) · 995 Bytes
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Use Python ESM example</title>
</head>
<body>
<script>
window.process = { env: { NODE_ENV: 'production' } };
</script>
<script type="module">
import { usePython } from "https://unpkg.com/usepython@0.0.10/dist/py.esm.js";
const py = usePython();
const unbindInstallLog = py.installLog.listen((val) => {
console.log(`Installing Python, stage ${val.stage}: ${val.msg}`)
})
console.log("Loading Python");
await py.load();
unbindInstallLog();
console.log("Python is ready");
py.log.listen((val) => {
console.log("LOG", val.stdOut)
});
const script = `print('ok from python')`;
const { result, error } = await py.run(script);
console.log("Error", error);
console.log("Result", result);
</script>
</body>
</html>