我如何将python脚本包含在HTML文件中? [英] How can I include python script in a HTML file?

查看:115
本文介绍了我如何将python脚本包含在HTML文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何放置这个python脚本:

How do I put this python script:

a = ['f','d','s','a']
x = -1
scope = vars()
for i in a:
    scope['x']+=1
    print a[x]

在html文件中?

inside of a html file?

推荐答案

类似这样的,如果你想创建一个html,不一定要显示它:

Something like this, if you want to create an html, not necessarily display it:

 html_file = open('namehere.html','w')
 a = ['f','d','s','a']
 x = -1
 scope = vars()
 data = ''
 for i in a: #TIP: use a generator
     scope['x']+=1
     data += a[x]
     data += '\n'
 html_file.write(data)
 html_file.close()

这篇关于我如何将python脚本包含在HTML文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆