python - 在 HTML 中运行 Python 脚本

标签 python html python-2.7

我正在做一个学校项目。我以前做过很多 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/

相关文章:

python - 如何设置SocketServer的最大连接数

python - 如何验证用户 "owns"是否是模型实例

html - formtarget ="_blank"在我的提交按钮中也不起作用提交后输入类型提交

python2.7 : [SSL: UNKNOWN_PROTOCOL] unknown protocol

python - 如何在 Python 中声明一个长字符串?

python - 无法使用 xpath、lxml 从抓取的页面获取脚本标记的内容

html - 不在纸质 Material 内的 NEON 动画页面

html - Span-within-a-span背景颜色优先级

python - 更改状态栏中坐标文本的格式

python-3.x - 如何让我的脚本选择正确的 python 解释器?