我正在做一个学校项目。我以前做过很多 Python 脚本,我想知道我是否可以像 javascript 一样在 html 中导入 python?我应该怎么做?例如导入时间。我想通过 python 脚本在我的网页中显示时钟。
最佳答案
有JS写的python实现。但是你不能在浏览器中运行“本地”python,你实际上可以通过 javascript 运行 python 代码或者将 python 代码编译为 js (llvm emscripten)
您正在寻找:
- 雕塑 - http://www.skulpt.org/
- 布莱顿 - http://www.brython.info/
- pyjs - http://pyjs.org/
- 睡衣
而恕我直言最值得一看的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在浏览器中的缺点
- 性能(我发现只有pypy.js提供benchmarks)差了N倍
- js 解释器库(需要加载/运行 python 代码),有几 MB 的大小
这两个是这样的,为什么那个项目,可能不应该在生产中使用,在那个阶段如果有的话。还有更多缺点,例如兼容性、实现完成...
关于python - 在 HTML 中运行 Python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251551/