python连接mysql
时间:2021-07-01 10:21:17
帮助过:20人阅读
__future__ import division
import pymysql
coon =
pymysql.connect(
host =
‘‘,user =
‘r‘,passwd =
‘bQ‘,
port =,db =
‘‘,charset =
‘‘
)
f =file(
‘ddd.txt‘)
i =
0
p_id_dic =
{}
lists =
[]
cur =
coon.cursor()
for line
in f:
i +=
1
chunk = line.strip().split(
‘\t‘)
p_id = chunk[
0]
price = round(
float(chunk[
2]) /
1,
2)
p_id_dic[int(p_id)] =
price
lists.append(p_id)
if i %
1000:
sql =
"select p_id, pay_price,total_price from map_ugc_core.task_package where p_id in (%s)" %
‘,‘.join(lists)
cur.execute(sql)
res =
cur.fetchall()
for db_pid, db_price,total_price
in res:
if abs(db_price - p_id_dic.
get(db_pid)) >
0.01:
print db_pid, db_price, p_id_dic.get(db_pid), db_price - p_id_dic.
get(db_pid), total_price
lists =
[]
if lists:
for db_pid, db_price, total_price
in res:
if abs(db_price - p_id_dic.
get(db_pid)) >
0.01:
print db_pid, db_price, p_id_dic.get(db_pid), db_price - p_id_dic.
get(db_pid), total_price
cur.close()
coon.close()
python连接mysql
标签:visio 连接 where har task imp 连接mysql ice bsp