[英]How do I a display a list as a table within an email body string?
I currently have a list derived from a data frame field and want to display that list as a table within a string.我目前有一个从数据框字段派生的列表,并希望将该列表显示为字符串中的表格。
I am stuck on displaying that list as a table within the body string of the email instead of outside.我坚持将该列表显示为 email 正文字符串中的表格,而不是外部。
My ultimate goal is to automatically create table rows from the name list instead of manually creating html script for each individual row/name.我的最终目标是从名称列表自动创建表行,而不是为每个单独的行/名称手动创建 html 脚本。 Any help would be appreciated, thank you.
任何帮助将不胜感激,谢谢。
The list looks like:该列表如下所示:
names = [John Appleseed, Amy Adams, Robert Feller]
and want to show that as a one column table (without that blank right column):并希望将其显示为单列表(没有空白的右列):
Names![]() |
|
---|---|
John Appleseed![]() |
|
Amy Adams![]() |
|
Robert Feller![]() |
So far, I have something like:到目前为止,我有类似的东西:
subject = 'Test'
body = """
hello, here is your email
"""
email_to = ['jackdaniels@gmail.com']
email(email_to, subject, body, email.config, attachment]
If you want an HTML table created automatically:如果你想自动创建一个 HTML 表:
from tabulate import tabulate
names = ['John Appleseed', 'Amy Adams', 'Robert Feller']
names = [[x] for x in names]
table= tabulate(names,tablefmt='html',headers=["Names"],stralign=("left",))
body = body + table
If you want plain text change tablefmt 'to pretty' or 'simple'如果你想要纯文本更改 tablefmt 'to pretty' 或 'simple'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.