如何用pyscript在网页里面写Python程式
Admin 2022-09-27 群英技术资讯 1475 次浏览
今天就跟大家聊聊有关“如何用pyscript在网页里面写Python程式”的内容,可能很多人都不太了解,为了让大家认识和更进一步的了解,小编给大家总结了以下内容,希望这篇“如何用pyscript在网页里面写Python程式”文章能对大家有帮助。根据 Anaconda 的项目 pyscript,可以将 python 的代码直接写在网页中,目前只支援两种标签,分别是<py-script> 与 <py-repl>,以下是简单的示例。
使用这两行导入 pyscript
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" rel="external nofollow" rel="external nofollow" /> <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
使用<py-repl>标签,会显示原始码,可以单击左下角的按键,开始运行。
<py-repl>
from datetime import datetime
now = datetime.now()
print("目前日期时间", now.strftime("%m/%d/%Y, %H:%M:%S"))
list1 = list("Pythony在网页中执行")
for i in list1:
print("{}".format(i))
</py-repl>
效果如下:

使用<py-repl>标签的结果,原则上是使用非同步处理,所以与主画面渲染比较会有延迟。
使用<py-script>标签
<py-script>
from datetime import datetime
now = datetime.now()
print("目前日期时间", now.strftime("%m/%d/%Y, %H:%M:%S"))
list1 = list("Pythony在网页中执行")
for i in list1:
print("{}".format(i))
</py-script>
效果如下:

使用<py-script>标签的结果
完整程式范例如下。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>第一个 PyScript 练习</title>
<link rel="icon" type="image/png" href="favicon.png" rel="external nofollow" />
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" rel="external nofollow" rel="external nofollow" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
在网页中撰写 Python 程式<br>
显示目前时间与印出一个列表:
使用 py-repl 标签<br/>
<py-repl>
from datetime import datetime
now = datetime.now()
print("目前日期时间", now.strftime("%m/%d/%Y, %H:%M:%S"))
list1 = list("Pythony在网页中执行")
for i in list1:
print("{}".format(i))
</py-repl>
使用 py-script 标签<br/>
<py-script>
from datetime import datetime
now = datetime.now()
print("目前日期时间", now.strftime("%m/%d/%Y, %H:%M:%S"))
list1 = list("Pythony在网页中执行")
for i in list1:
print("{}".format(i))
</py-script>
</body>
</html>
pyscript,https://pyscript.net/
PyScript,https://github.com/pyscript/pyscript
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
今天看到了一个比较诡异的写法,for后直接跟了else语句,起初还以为是没有缩进好,查询后发现果然有这种语法,特此分享。之前写过c++和Java,在for后接else还是第一次见。
这篇文章主要为大家介绍了python深度学习tensorflow1.0参数初始化initializer示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
Sklearn(全称 SciKit-Learn),是基于 Python 语言的机器学习工具包。Sklearn 主要用Python编写,建立在 Numpy、Scipy、Pandas 和 Matplotlib 的基础上,也用 Cython编写了一些核心算法来提高性能。
对于扫雷游戏相信大家应该都不陌生吧,扫雷游戏可以说是很经典的游戏了,之前我们了解了使用介绍实现扫雷游戏,这篇文章我们就来尝试使用python做一个扫雷游戏,感兴趣的朋友就接着往下看吧。
这篇文章主要介绍了Python Opencv中获取卷积核的实现代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008