#-*- 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