python连接mysql
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() 相关推荐
  迷途风景    2020-07-28  
   wyqwilliam    2020-06-13  
   JamesRayMurphy    2020-05-31  
   usepython    2020-05-28  
   gululululu    2020-05-28  
   爱文学更爱编程    2020-05-26  
   llltaotao    2020-05-19  
   ericxieforever    2020-05-07  
   zhongzhiwei    2020-05-08  
   zjyhll    2020-05-06  
   bcbeer    2020-04-16  
   景泽元的编程    2020-04-16  
   jhshanyu00    2020-04-10  
   gululululu    2020-03-20  
   URML    2020-02-22  
   Yasin    2020-02-13  
   waiwaiLILI    2020-02-03  
   wintershii    2020-02-01