av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Python教程:python如何導(dǎo)入txt數(shù)據(jù)庫(kù)?

python將TXT數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫(kù)的方法代碼如下:

#!/usr/bin/python
#coding=utf-8

import _mysql,sys,time
#讀入數(shù)據(jù)函數(shù)
def add_data(id,name,created_time):
    try:
        conn=_mysql.connect('127.0.0.1','root','')
        conn.query("set names utf8")
        conn.query("insert into mysql.test3(%s,%s,%s) values('%s','%s','%s')"%('object_id','object_name','created',id,name,created_time))
        result=conn.use_result()
        conn.close()
    except _mysql.Error,e:
        print ("error %d:%s" % (e.args[0],e.args[1]))
        sys.exit(1)
if __name__ =="__main__":
    f= open("/opt/testdata/aaa.txt","r")
	
    time1=time.time()
    print time.ctime()
	#讀出第一行數(shù)據(jù),作為數(shù)據(jù)表的段名
    line=f.readline()
    content=line.strip().split(",")
    conn0=_mysql.connect('127.0.0.1','root','')
    print 'connection is builded succesfully'
    conn0.query("drop table if exists mysql.test3")
    conn0.query("create table mysql.test3(%s varchar(90),%s varchar(90),%s varchar(90))"%(content[0][1:-1],content[1][1:-1],content[2][1:-1]))
    conn0.close()
    #運(yùn)用next函數(shù),讓for循環(huán)從第二行開始讀數(shù)據(jù)
    next(f)
    for line in f:
	   #做一些處理,讓每一段分開,放置在一個(gè)列表中
       content=line.strip().split(",")
       add_data(id=content[0][1:-1],name=content[1][1:-1],created_time=content[2][1:-1])
       
    f.close()
	
    time2=time.time()
    print time.ctime()
	#計(jì)算導(dǎo)入數(shù)據(jù)的時(shí)間
    print 'importing time is %f'%(time2-time1)

新聞標(biāo)題:創(chuàng)新互聯(lián)Python教程:python如何導(dǎo)入txt數(shù)據(jù)庫(kù)?
轉(zhuǎn)載注明:http://uogjgqi.cn/article/ccoosij.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流