如何在python中通过电子邮件正确发送表格? [英] How to send correctly a table by email in python?
问题描述
我试图通过电子邮件发送ASCII表,但是收到消息时出现了意外格式
i trying to send a ASCII table by email but when i received i got a unexpected format
Python脚本中显示的格式为
the format that shows in my python script is
from tabulate import tabulate
message_launch = ['value','value2','value3','value4','value5','value6']
headers = ['data_a','data_b','data_c','data_d','date_e','data_f']
**t = tabulate(message_launch, headers=message_headers, missingval='?', stralign='center', tablefmt='grid').encode('utf-8')**
(Pdb) type(t)
<type 'str'>
+ ------------ + ------ --- + ------------ + ---------- + ---------------- + ----- --------- +
| data_a | data_b | data_c | data_d | data_e | data_f |
+ ============ + ========== + ==================== == + =============== + ============= +
| value1 | value2 | value3 | value4 | value5 | value6 |
+ ------------ + ---------- + ------------ + -------- -+ ---------------- + -------------- +-+
+------------+----------+------------+----------+----------------+--------------+ | data_a | data_b | data_c | data_d | data_e | data_f | +============+==========+============+==========+================+==============+ | value1 | value2 | value3 | value4 | value5 | value6 | +------------+----------+------------+----------+----------------+--------------+-+
我从电子邮件中获得的表格非常混乱
我如何以正确的方式通过电子邮件接收表格?
and the table that i got from my email is very disordered how can i receive in the correct the way the table by email ?
推荐答案
大多数电子邮件客户端都支持html呈现。我认为那是最简单的方法。
Most email clients support html rendering. I think that would be the easiest way.
将'html'
传递到 tablefmt
:
t =列表(message_launch,headers = message_headers,missingval ='?',stralign ='center',tablefmt ='html')。encode( 'utf-8')
然后使用任何电子邮件库将 t
发送为html您正在使用。
Then send t
as html with whatever email library you are using.
这篇关于如何在python中通过电子邮件正确发送表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!