标签:python
同事说大文本文件打不开,写个程序分割下就行了啊。。。#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# author: edit by infaaf
# mail: infaaf@126.com
# split big file per 10000
with open(‘source.txt‘) as f:
linenum = 1
filenum=1
for line in f:
if linenum >3:
linenum=1
filenum+=1
with open(‘sourcesplit_%s‘%filenum,‘a‘) as outf:
outf.write(line.strip()+"\n")
print("linenum: %s, filenum: %s"%(linenum,filenum))
print(line.strip())
linenum+=1
标签:python
原文地址:http://blog.51cto.com/13606158/2092860