當前位置:首頁 » 編程語言 » 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就行了。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:710
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:973
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:684
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:836
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:742
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1083
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:313
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:193
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:881
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:839