电子邮件格式列表

时间:2014-11-20 13:36:51

标签: python string list python-2.6

我有脚本,它收集一些数据:

...
REPORT = []
...
if re.search('^-', line):
    logging.info('File %s in line %d: %s' % (file, num, line))
    REPORT.append('File %s in line %d: %s' % (file, num, line))
...

然后发送电子邮件:

body = email.mime.Text.MIMEText("""

Report:

%s

""" % REPORT)

msg.attach(body)

但是它会以'原始'视图到达,例如:

  

报告:

['File services.PROD.properties in line 29: - \r\n', 'File services.PROD.properties in line 30: - Url=https://someurl.com/reporting\r\n', 'File services.properties in line 44: - gUrl=http://someurl.com:11704/uu.dll\r\n', ']

如何格式化以发送常用的行/字符串?

Python 2.6

1 个答案:

答案 0 :(得分:3)

使用str.join通过换行符连接字符串:

>>> '\n'.join(['line1', 'line2', 'line3'])
'line1\nline2\nline3'
>>> print('\n'.join(['line1', 'line2', 'line3']))
line1
line2
line3

body = email.mime.Text.MIMEText("""

Report:

%s

""" % '\n'.join(REPORT))