python - 如何在 HTML 文件中包含 python 脚本?

标签 python html

我如何放置这个 python 脚本:

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

在 html 文件中?

最佳答案

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

 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 文件中包含 python 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4161332/

相关文章:

python - 在 numpy 中创建非等距数组的函数

python - 如何动态填充前导零(在函数中)?

python - 如果路径是文件或目录 (Python)

python - Keras fit_generator() - 时间序列的批处理如何工作?

php - 如何在wordpress中插入自定义图像和html

html - 在 html img 标签( Angular )中显示 ngCordova 存储的图像

html - jqgrid内联编辑显示html标签

Python glob,os,相对路径,将文件名制作成列表

javascript - 如何禁用 JavaScript 中的 href 链接?

javascript - 如何启动我的线上和线下事件