电子邮件正文中的Python:preety表输出

时间:2018-11-21 17:47:31

标签: python sql-server email html-table

我正在研究python,我需要将查询结果转换为电子邮件,并且使用了漂亮的表并将SQL查询结果转换为表,但是问题是我体内需要此输出表电子邮件。

我们该怎么做?

import pyodbc
from prettytable import PrettyTable

xi = PrettyTable(['Job ID','Desc'])



xi.padding_width = 1


con = pyodbc.connect('DRIVER={SQL Server};SERVER=SNLdb2;DATABASE=InternalUseOnly;Trusted_Connection=yes')

cur = con.cursor()

db_cmd = ("""select  pi.ProcessInstanceAppianID,pi.ProcessInstanceDescription
                    from InternalUseOnly..ProcessInstance pi
                   where pi.KeyProcessStream in (11994)
                     and UpdOperation <> 2
                     and pi.ProcessInstanceCompleted is  null
                         order by pi.KeyProcessInstance
               """)
res = cur.execute(db_cmd)
for data in res:
    xi.add_row([data[0],data[1]])


print(xi)

0 个答案:

没有答案
相关问题