显示和迭代字符串中的列表? [英] Displaying and iterating a list within a string?

查看:72
本文介绍了显示和迭代字符串中的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在编写一个程序,其中一部分涉及发送电子邮件.

So I'm writing a program which part of it involves sending out an email.

在电子邮件正文(是一个字符串)中,我想显示一个列表.但是,我想知道如何/或最好的方法来执行此操作,因为现在,它仅(自然)仅显示列表的第一个元素.如您所见,我要在底部列出的列表是:

Within the email body (which is a string), I want to display a list. However, I want to know how/or what the best way to do this because right now, it only displays the first element of the list (naturally). As you can see, the list I'm trying to put in at the bottom is:

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)

推荐答案

只需>加入换行符(或逗号,或任何您喜欢的内容)上的列表:

Just join the list on newlines (or commas, or whatever you like) as you format it:

"""…booked for %s:

%s

Thank You, …""" % (newdate, "\n".join(formatted_times))

这篇关于显示和迭代字符串中的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆