python分割大型txt文件

#每3000000行拆成一个文件
wdata = []
count = 0
with open('baike_triples.txt', 'r', encoding='utf8') as f:
    d = f.readline()
    while d:
        if count%3000000==0:
            print(count)
            with open("pass_" + str(count) + ".txt", 'w+',encoding='utf-8') as f_target:
                for mydata in wdata:
                    f_target.write(mydata)
                  wdata = []
        count+=1
        wdata.append(d)
        d = f.readline()

你可能感兴趣的:(数据预处理,python,列表)