txt文件分解为固定条数的文件
生活随笔
收集整理的這篇文章主要介紹了
txt文件分解为固定条数的文件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#-*- coding: UTF-8 -*-
# import linecache
# count = linecache.getline(filename,linenum)
# 讀取文件某一行的內(nèi)容
# str = linecache.getlines(filename)
# str為列表形式,每一行為列表中的一個元素
import sys
import linecachereload(sys)
sys.setdefaultencoding( "utf-8" )# 分解一個txt文件為固定條數(shù)的文件
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
?
轉(zhuǎn)載于:https://www.cnblogs.com/oneby/p/5454297.html
總結(jié)
以上是生活随笔為你收集整理的txt文件分解为固定条数的文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IE这回在css flex中扳回一局?
- 下一篇: FreeMarker 一二事 - 静态模