1
我的輸出來的字符串中的「L」:在臨時表中的總記錄(3L) 我只希望數n支架和如何刪除L, 林轉換查詢爲str因爲我不能concanete第一部分和味精發送電子郵件,但消除蟒蛇
#!/usr/bin/env python
import csv
import MySQLdb
import pysftp
import smtplib
import sys
#connection to Database
conn = MySQLdb.connect(host="XXXXX", # The Host
user="XXXXX", # username
passwd="XXXXX", # password
db="XXXXX") # name of the data base
part1 = """From: XXXXX
To: To Person <XXXXX.com>
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP HTML e-mail test
Toatal records in Staging Table inserted:
"""
sender = 'XXXXX'
receivers = ['XXXXX','XXXXX']
x = conn.cursor()
query = "select count(*) as toatal_records_inserted from fpwbs_feed_stg"
x.execute(query)
msg = ""
for row in x.fetchall():
msg += str(row)
msg=part1+msg
smtpObj=smtplib.SMTP('XXXXX', 25)
smtpObj.sendmail(sender, receivers, msg)
這將是更好的只是抓住一切,但最後一個字符,因爲數量可能超過1個digit:'msg + = str(row [: - 1])' – user2896976
@ user2896976:它在一個元組中,所以這隻會從元組中拉出整數。 – bernie
對不起,沒有看到它是在一個元組。然後使用'row [0] [: - 1]'。 – user2896976