Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
beichen1001
pyodide_350102
提交
929e0040
P
pyodide_350102
项目概览
beichen1001
/
pyodide_350102
与 Fork 源项目一致
Fork自
inscode / HTML-CSS-JS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pyodide_350102
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
929e0040
编写于
8月 10, 2023
作者:
W
weixin_68179602
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Aug 10 20:27:00 CST 2023 inscode
上级
d877dbfd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
42 deletion
+44
-42
index.html
index.html
+23
-41
worker.js
worker.js
+21
-1
未找到文件。
index.html
浏览文件 @
929e0040
<!
DOCTYPE
html>
<!
doctype
html>
<html>
<head>
<script>
const
worker
=
new
Worker
(
"
worker.js
"
);
worker
.
postMessage
(
'
import sys
\n
sys.version
'
);
const
promise
=
new
Promise
(
function
(
resolve
,
reject
)
{
worker
.
onmessage
=
function
(
event
)
{
var
output
=
event
.
data
;
console
.
log
(
output
);
resolve
();
};
});
promise
.
then
(
function
()
{
var
scriptTag
=
document
.
querySelector
(
'
script[id="script"]
'
);
var
pythonCode
=
'
print(5/2)
'
;
console
.
log
(
scriptTag
.
textContent
);
worker
.
postMessage
(
pythonCode
);
<script
src=
"https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js"
></script>
</head>
worker
.
onmessage
=
function
(
event
)
{
var
output
=
event
.
data
;
console
.
log
(
output
);
};
});
/*
(function(){
<body>
<script>
let
interpreter
;
})()
async
function
init
()
{
interpreter
=
await
loadPyodide
();
console
.
log
(
interpreter
.
runPython
(
`import sys\nsys.version`
));
main
();
}
function
main
()
{
var scriptTag = document.querySelector('script[id="script"]');
var pythonCode = 'print(5/2)';
console.log(scriptTag.textContent);
worker.postMessage(pythonCode);
pyScriptRun
();
}
worker.onmessage = function (event)
{
var output = event.data;
console.log(output
);
};
function
pyScriptRun
()
{
document
.
querySelectorAll
(
'
script[type="text/python"]
'
).
forEach
(
scriptTag
=>
{
interpreter
.
runPython
(
scriptTag
.
innerHTML
);
}
)
;
}
window.onload = main;
*/
init
();
</script>
</head>
<body>
<script
id=
"script"
type=
"text/py"
>
print
(
5
/
2
)
</script>
<script
type=
"text/python"
>
print
(
5
/
2
)
</script>
<script
type=
"text/python"
>
print
(
5
/
3
)
</script>
<py-repl
id=
"repl"
>
print(5/3)
</py-repl>
</body>
</html>
\ No newline at end of file
worker.js
浏览文件 @
929e0040
importScripts
(
"
https://cdn.jsdelivr.net/pyodide/v0.23.4/full/pyodide.js
"
);
let
interpreter
;
async
function
init
(){
interpreter
=
await
loadPyodide
();
interpreter
.
runPython
(
"
import sys
\n
sys.version
"
).
then
((
result
)
=>
{
console
.
log
(
result
)
})
}
self
.
addEventListener
(
'
message
'
,
function
(
event
)
{
console
.
log
(
"
1
"
)
var
data
=
event
.
data
;
switch
(
data
.
type
)
{
case
'
init
'
:
init
();
break
;
case
'
event2
'
:
console
.
log
(
"
event2
"
);
break
;
}
});
/*
async function run() {
let pyodide = await loadPyodide();
var pythonCode = self.pyCode; // 获取主线程发送的 Python 代码
...
...
@@ -13,5 +33,5 @@ self.onmessage = function(event) {
console.log(self.pyCode)
run();
};
*/
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录