コードの何が問題になっていますか? ありがとうございました
import os
import os.path
import time
global item_count
#-*- coding: cp936 -*-
import MySQLdb
import MySQLdb.cursors
import threading
import multiprocessing
from time import sleep,ctime
def qucun():
#connect to mysql
conn=MySQLdb.connect(host="localhost",user="root",passwd="caihong")
cursor=conn.cursor()
try:
cursor.execute("""create database if not exists quad""")
except:
print 'Quad is exist'
conn.select_db('quad')
conn=MySQLdb.connect(host="localhost",user="root",passwd="caihong",db="quad")
#get cursor
cursor=conn.cursor()
try:
cursor.execute("""create table if not exists record(fn1 varchar(100),
fn2 varchar(100),fn3 varchar(100),fn4 varchar(100),
fn5 varchar(100),fn6 varchar(100),fn7 varchar(100),fn8 varchar(100))""")
except:
print 'Table record is exist'
loops=['2013071818_1.txt','2013071818_2.txt','2013071818_3.txt','2013071818_4.txt','2013071818_5.txt']
def loop(nloop,filename):
print 'This loop%s start at:'%nloop,ctime()
#connect to quad
conn=MySQLdb.connect(host="localhost",user="root",passwd="caihong",db="quad")
conn.select_db('quad')
#get cursor
cursor=conn.cursor()
newitem=open('C:\\Python27\\caihong\\%s'%filename,'r')
data=[line.strip() for line in newitem.readlines()]
print data
##put data into value
values=['%s'%data[0],'%s'%data[1],'%s'%data[2],'%s'%data[3],'%s'%data[4],
'%s'%data[5],'%s'%data[6],'%s'%data[7]]
cursor.execute("""insert into record values(%s,%s,%s,%s,%s,%s,%s,%s)""",values);
conn.commit()
cursor.close()
sleep(2)
print 'This loop done at',ctime()
if __name__=='__main__':
print 'starting at:',ctime()
threads=[]
nloops=range(len(loops))
pool=multiprocessing.Pool(processes=2)
for i in nloops:
t=pool.apply_async(loop,(i,loops[i]))
pool.close()
pool.join()
if t.successful():
print 'successful'
print 'all Done at:',ctime()
os.system("pause")
qucun()