txt文件匹配脚本

# -*- coding:utf-8 -*-

import time
start = time.clock()
data=open("Data.txt","r")
PipeiData=open("PipeiData.txt","r")


#目标文件,所有匹配数据产出在该文件中
result=open("result.txt","w")

dict={}
for k in data:
    k=k.strip()
    k=k.split('	')
    k1=k[0]#id
    k2=k[1]#注册时间
    dict[k1]=k2


'''
for k,v in dict.iteritems():
    print k,v
'''


for y in PipeiData:
    y=y.strip()
    y=y.split('	')
    y1=y[0]#充值ID
    y2=y[1]#充值金额
    y3=y[2]#充值时间
    #print y1,y2,y3
    if y1 in dict:
        yy1=y1
        yy2=dict[y1]#注册时间
        ss=yy2+'	'+yy1+'	'+y2+'	'+y3
        result.write(ss+'
')


result.close()
print '数据匹配完毕'

end = time.clock()
print "运行时长: %f s" % (end - start)
原文地址:https://www.cnblogs.com/dengyg200891/p/5743853.html