TOP

Python 逐行分割大txt文件
2017-10-10 21:05:46 】 浏览:10042
Tags:Python 分割 txt 文件

# -*- 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文件 https://www.cppentry.com/bencandy.php?fid=77&id=136348

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用python操作mysql 下一篇通过pip安装scrapy包时出现错误:U..