亚洲AVI,黑人巨茎大战欧美白妇,初高中生洗澡自慰高清网站,欧美日韩无砖专区一中文字

重慶分公司,新征程啟航

為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)

python導(dǎo)入txt數(shù)據(jù)庫的方法-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

成都創(chuàng)新互聯(lián)成都企業(yè)網(wǎng)站建設(shè)服務(wù),提供網(wǎng)站制作、網(wǎng)站設(shè)計(jì)網(wǎng)站開發(fā),網(wǎng)站定制,建網(wǎng)站,網(wǎng)站搭建,網(wǎng)站設(shè)計(jì),響應(yīng)式網(wǎng)站設(shè)計(jì),網(wǎng)頁設(shè)計(jì)師打造企業(yè)風(fēng)格網(wǎng)站,提供周到的售前咨詢和貼心的售后服務(wù)。歡迎咨詢做網(wǎng)站需要多少錢:18982081108

不懂python導(dǎo)入txt數(shù)據(jù)庫的方法?其實(shí)想解決這個(gè)問題也不難,下面讓小編帶著大家一起學(xué)習(xí)怎么去解決,希望大家閱讀完這篇文章后大所收獲。

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

#!/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)

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享python導(dǎo)入txt數(shù)據(jù)庫的方法內(nèi)容對大家有幫助,同時(shí)也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,遇到問題就找創(chuàng)新互聯(lián),詳細(xì)的解決方法等著你來學(xué)習(xí)!


分享標(biāo)題:python導(dǎo)入txt數(shù)據(jù)庫的方法-創(chuàng)新互聯(lián)
分享地址:http://news.spvevtbd.cn/article/djodsp.html

其他資訊

在線咨詢
服務(wù)熱線
服務(wù)熱線:028-86922220
TOP