码迷,mamicode.com
首页 > 编程语言 > 详细

Python 逐行分割大txt文件

时间:2017-10-10 10:01:10      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:lin   continue   txt   file   log   +=   count   odi   append   

# -*- coding: <encoding name> -*-
import io
LIMIT = 150000
file_count = 0
url_list = []

with io.open(D:\DB_NEW_bak\DB_NEW_20171009_bak.sql,r,encoding=utf-16) as f:
    for line in f:
        url_list.append(line)
        if len(url_list) < LIMIT:
            continue
        file_name = str(file_count)+".sql"
        with io.open(file_name,w,encoding=utf-16) as file:
            for url in url_list[:-1]:
                file.write(url)
            file.write(url_list[-1].strip())
            url_list=[]
            file_count+=1
if url_list:
    file_name = str(file_count) + ".sql"
    with io.open(file_name,w,encoding=utf-16) as file:
        for url in url_list:
            file.write(url)
print(done)

 

Python 逐行分割大txt文件

标签:lin   continue   txt   file   log   +=   count   odi   append   

原文地址:http://www.cnblogs.com/freeliver54/p/7643932.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!