Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将字符串列表格式化为html表?_Python_Html_Python 3.x_List - Fatal编程技术网

Python 如何将字符串列表格式化为html表?

Python 如何将字符串列表格式化为html表?,python,html,python-3.x,list,Python,Html,Python 3.x,List,我正在尝试用gmail发送一条示例消息。我的邮件包含一个项目列表的文本。我想以表格格式打印每个列表项。现在我正在尝试使用新行,但每次字符串长度不同时,它都无法与电子邮件正确对齐。有人能告诉我如何在邮件中保留列表项吗 下面是我正在尝试的演示代码 def html_table(list_name): print('<table>') for sublist in list_name: print(' <tr><td>') print(su

我正在尝试用gmail发送一条示例消息。我的邮件包含一个项目列表的文本。我想以表格格式打印每个列表项。现在我正在尝试使用新行,但每次字符串长度不同时,它都无法与电子邮件正确对齐。有人能告诉我如何在邮件中保留列表项吗

下面是我正在尝试的演示代码

def html_table(list_name):
  print('<table>')
  for sublist in list_name:
    print('  <tr><td>')
    print(sublist)
    print('  </td></tr>')
  print('</table>')

l = ["--> ServiceName is ec2 , this is a sample string inside list item1    ",
     "-------- ServiceName is s3 , this message is a sample string inside list item2------"]
message = """
    Hi ,
    The following are different aws services  
    {0}
    Best regards,
    Team
    """.format('\n\t'.join(map(str, l)))

print(message)
def html_表(列表名称):
打印(“”)
对于列表\u名称中的子列表:
打印(“”)
打印(子列表)
打印(“”)
打印(“”)
l=[“-->ServiceName是ec2,这是列表项1中的一个示例字符串”,
“-----ServiceName是s3,此消息是列表项2中的示例字符串-------”]
message=”“”
你好
以下是不同的aws服务
{0}
顺致敬意,
团队
“”格式('\n\t'.join(映射(str,l)))
打印(信息)

您考虑过这样的模块吗?我不知道,让我检查一下。感谢您提供的信息还请检查您的电子邮件程序是否使用固定宽度字体-大多数情况下,不同的字母具有不同的宽度,您将无法简单地用空格“隔开”文本。您可以将html表添加到邮件中。