所以我正在编写一个程序,其中一部分涉及发送电子邮件。
在电子邮件正文(这是一个字符串)中,我想显示一个列表。但是,我想知道如何/或者最好的方法是什么,因为现在,它只显示列表的第一个元素(当然)。正如您所看到的,我想在底部放入的列表是:
formatted_times
以下是以下代码:
FROM = gmail_user
TO = ['mcgoga12@wfu.edu']
SUBJECT = "StudyBug - Study Rooms for %s" % newdate
TEXT = """
This is an automated email from StudyBug.
We wanted to let you know that the following studyrooms were booked for %s:
%s
Thank You,
StudyBug
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
Check out the project page!: https://github.com/g12mcgov/StudyBug
""" % (newdate, formatted_times)
答案 0 :(得分:2)
在格式化时,只需join新行(或逗号,或任何您喜欢的)列表:
"""…booked for %s:
%s
Thank You, …""" % (newdate, "\n".join(formatted_times))