gpt4 book ai didi

python - 在 HTML 中运行 Python 脚本

转载 作者:太空狗 更新时间:2023-10-30 02:58:21 25 4
gpt4 key购买 nike

我正在做一个学校项目。我以前做过很多 Python 脚本,我想知道我是否可以像 javascript 一样在 html 中导入 python?我应该怎么做?例如导入时间。我想通过 python 脚本在我的网页中显示时钟。

最佳答案

有JS写的python实现。但是你不能在浏览器中运行“本地”python,你实际上可以通过 javascript 运行 python 代码或者将 python 代码编译为 js (llvm emscripten)

您正在寻找:

而恕我直言最值得一看的pypy.js:

PyPy.js is an experiment in building a fast and compliant python environment for the web.

It uses the PyPy python interpreter, compiled for the web via emscripten, with a custom JIT backend that emits asm.js code at runtime.


Python在浏览器中的缺点

  1. 性能(我发现只有pypy.js提供benchmarks)差了N倍
  2. js 解释器库(需要加载/运行 python 代码),有几 MB 的大小

这两个是这样的,为什么那个项目,可能不应该在生产中使用,在那个阶段如果有的话。还有更多缺点,例如兼容性、实现完成...

关于python - 在 HTML 中运行 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com