Augis
Augis

Reputation: 79

Python loop in emails body

I have this html email body and trying to put a loop to structure a list nicely.

item = (["<li>{}</li>".format(x) for x in list])
html = """\
<html>
  <body>
    <p>hi:<br>
       <br>
       """ +  str(item) +"""
    </p>
  </body>
</html>
"""

The list:

['mango', 'peach', 'banana', 'apple']

Desired result in email:

mango

peach

banana

apple

Current result:

["

'
mango
', '
peach
', '
banana
', '
apple']

"] 

Upvotes: 0

Views: 376

Answers (1)

pacuna
pacuna

Reputation: 2089

You need to use str.join instead of casting to a string:

' '.join(item)

Upvotes: 3

Related Questions