码迷,mamicode.com
首页 > 数据库 > 详细

python连接mysql

时间:2019-12-08 01:31:44      阅读:36      评论:0      收藏:0      [点我收藏+]

标签:visio   连接   where   har   task   imp   连接mysql   ice   bsp   

 

from __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   

原文地址:https://www.cnblogs.com/kaituorensheng/p/12003977.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!