简体   繁体   English

如何在 email 正文字符串中将列表显示为表格?

[英]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.

相关问题 如何从表中 SELECT 特定名称,并将它们显示在 email 的正文中? - How do I SELECT specific names from a table, and display them in the body of an email? 如何在python的电子邮件正文中打印多行字符串变量 - How do I print a variable which is multiline string in the body of email in python 如何将字符串的长度与同一列表中的 integer 进行比较? - How do I compare the length of a string to an integer within the same list? 如何判断是否在较大的字符串中找到了字符串列表? - How do I tell if a list of strings are found within a larger string? 如何计算字符串是否在列表的子字符串内? - How do I count if a string is within the substrings of a list? 如何检查字符串列表中的字符串中是否存在大写字母? - How do I check if there is a uppercase letter in a string within a list of strings? 在电子邮件正文中显示 Python HTML 表 - Display Python HTML Table in Body of Email 如何在 python 的电子邮件正文中使文本“粗体”? - How do I make text "bold" in email body in python? 如何使用 python 整齐地格式化 email 主体? - How do I neatly format an email body using python? 当发送 email 并在 email 的正文中显示该时间时,如何每分钟获取当前时间? - How would I get the current time every minute when an email is sent and display that time in the body of the email?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM