pyscript在网页怎样写Python程式,有什么要注意
Admin 2022-09-05 群英技术资讯 1160 次浏览
这篇文章给大家分享的是“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>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
如果想要充分利用,在python中大部分情况需要使用多进程,那么这个包就叫做multiprocessing。借助它,可以轻松完成从单进程到并发执行的转换。multiprocessing支持子进程、通信和共享数据、执行不同形式的同步,提供了Process、Queue、Pipe、Lock等组件。那么本节要介绍的内容有:ProcessLockSemaphoreQueuePipePoo
这篇文章主要为大家详细介绍了Python实现简单扫雷游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
这篇文章主要为大家介绍了python密码学RSA密码解密教程,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
getattr是python里的一个内建函数getattr()这个方法最主要的作用是实现反射机制。也就是说可以通过字符串获取方法实例。这样,你就可以把一个类可能要调用的方法放在配置文件里,在需要的时候动态加载。python里面跟getattr相关的有hasattr,setattr,delattr ,那么我们通过下面的例子,来详细的说说他们的用法。1classXiaorui:2
这篇文章主要介绍了python 中的pycrypto 算法加密,文章基于python的相关资料展开对pycrypto 算法加密的详细介绍,需要的小伙伴可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
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