首页 > 其他 > 详细

txt文件分解为固定条数的文件

时间:2016-05-03 12:09:39      阅读:250      评论:0      收藏:0      [点我收藏+]
#-*- coding: UTF-8 -*-
# import linecache
# count = linecache.getline(filename,linenum)
# 读取文件某一行的内容
# str = linecache.getlines(filename)
# str为列表形式,每一行为列表中的一个元素
import sys
import linecache

reload(sys)
sys.setdefaultencoding( "utf-8" )

# 分解一个txt文件为固定条数的文件
def recount_txt_number(txtpath,file_output_name,number):
    f=open(txtpath,"r")
    filename=file_output_name+".txt"
    for i in range(1,len(f.readlines())+1):
        count= linecache.getline(txtpath,i)
        with open(filename,"a") as output:
            output.write(count)
        if i%number==0:
            filename=file_output_name+str(i)+".txt"
            print filename

 

txt文件分解为固定条数的文件

原文:http://www.cnblogs.com/oneby/p/5454297.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!