-1

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

Here's the code below:

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)
kojiro
  • 74,557
  • 19
  • 143
  • 201
carbon_ghost
  • 1,114
  • 5
  • 18
  • 40

1 Answers1

2

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))
kojiro
  • 74,557
  • 19
  • 143
  • 201
  • This works great in stripping the "['']" from the list, however, I want to completely iterate through the entire list. This will only print the first element – carbon_ghost Apr 18 '14 at 02:07
  • 1
    @carbon_ghost Is `formatted_times` a flat list containing only strings? or is it nested, or does it contain things that are not strings? – kojiro Apr 18 '14 at 02:10
  • No, it's a flat list containing only strings. – carbon_ghost Apr 18 '14 at 02:12
  • 1
    @carbon_ghost then `gluestring.join` will list every item in the list. – kojiro Apr 18 '14 at 02:13
  • hmm... Can't find anything regarding a gluestring.join? Care to elaborate more? – carbon_ghost Apr 18 '14 at 02:18
  • @carbon_ghost open a terminal, type `python`, then type `help(''.join)`. Or just [look here](https://docs.python.org/3.5/library/stdtypes.html#str.join) – kojiro Apr 18 '14 at 02:19