怎样用python脚本生成一个html格式的测试报告

然后处理图片 for f in files:if f.lower().endswith('.jpg') or f.lower().endswith('.png'):html.write("" % f)html.write('')html.close()把这个python代码放在有图片和txt文本的目录里,运行就可以了。如果不是jpg,修改增加png,gif就行了。
怎样用python脚本生成一个html格式的测试报告
比如很简单的,可以这样:
# -*- coding:utf-8 -*-
import os,sys

html = open('index.html', 'w')
html.write("""
<html>
<head>
<title>Test</title>
<style>img{float:left;margin:5px;}</style>
</head>
<body>
""")

files = os.listdir('.')

# 首先处理文本
for f in files:
if f.lower().endswith('.txt'):
fp = open(f)
content = fp.read()
fp.close()
html.write("<p>%s</p>" % content)

# 然后处理图片
for f in files:
if f.lower().endswith('.jpg') or f.lower().endswith('.png'):
html.write("<img src='%s' />" % f)

html.write('</body></html>')
html.close()

把这个python代码放在有图片和txt文本的目录里,运行就可以了。如果不是jpg,修改增加png,gif就行了。2012-06-15
print "<html/>"2012-06-14
mengvlog 阅读 52 次 更新于 2025-10-30 08:14:16 我来答关注问题0
檬味博客在线解答立即免费咨询

Python相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部