Python 在电子邮件正文中循环
Python loop in emails body
我有这个 html 电子邮件正文并试图放置一个循环来很好地构建列表。
item = (["<li>{}</li>".format(x) for x in list])
html = """\
<html>
<body>
<p>hi:<br>
<br>
""" + str(item) +"""
</p>
</body>
</html>
"""
榜单:
['mango', 'peach', 'banana', 'apple']
电子邮件中的期望结果:
mango
peach
banana
apple
当前结果:
["
'
mango
', '
peach
', '
banana
', '
apple']
"]
您需要使用 str.join 而不是转换为字符串:
' '.join(item)
我有这个 html 电子邮件正文并试图放置一个循环来很好地构建列表。
item = (["<li>{}</li>".format(x) for x in list])
html = """\
<html>
<body>
<p>hi:<br>
<br>
""" + str(item) +"""
</p>
</body>
</html>
"""
榜单:
['mango', 'peach', 'banana', 'apple']
电子邮件中的期望结果:
mango
peach
banana
apple
当前结果:
["
'
mango
', '
peach
', '
banana
', '
apple']
"]
您需要使用 str.join 而不是转换为字符串:
' '.join(item)