【发布时间】:2022-02-04 04:57:55
【问题描述】:
我想在 python 中格式化我的 html 代码。
我的 Python 文件是:
titles = ['aaa', 'bbb', 'ccc', 'ddd', 'eee']
html_text = """<html>
<head>
<style type="text/css">
table { border-collapse: collapse;}
td { text-align: center; border: 5px solid #ff0000; border-style: dashed; font-size: 30px; }
</style>
</head>
<body>
<table width="100%" height="100%" border="5px">
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
<tr>
<td>%s</td>
</tr>
</table>
</body>
</html> % (titles[0], titles[1], titles[2], titles[3], titles[4])"""
f = open('temp.html', 'w')
f.write(html_text)
f.close()
我想让这些 %s 成为titles[0]、titles[1]、titles[2]、titles[3]、titles[4]。
我该怎么做?
【问题讨论】:
-
到目前为止你尝试过什么?编辑:我的坏没有看到滚动框的底部
-
@Brandon 代码,你没看到吗?