当前位置:首页 » 编程语言 » pythontext转html

pythontext转html

发布时间: 2025-08-15 14:25:58

‘壹’ 怎样用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就行了。

热点内容
20台电脑做服务器多少钱 发布:2025-08-15 16:32:01 浏览:585
eclipse编译的class 发布:2025-08-15 16:29:21 浏览:820
ftp后如何看服务器上的文件 发布:2025-08-15 16:23:56 浏览:980
红旗h5旗悦韵配置哪些功能 发布:2025-08-15 16:12:37 浏览:205
怎么会编程 发布:2025-08-15 16:12:32 浏览:458
一直都用安卓想换苹果要注意什么 发布:2025-08-15 16:01:11 浏览:217
微信小程序开发存储数据 发布:2025-08-15 15:40:54 浏览:930
24c编程器 发布:2025-08-15 15:39:15 浏览:543
安卓手机如何语音唤醒小布 发布:2025-08-15 15:34:19 浏览:779
smt编程教程视频 发布:2025-08-15 15:29:19 浏览:633