zoukankan      html  css  js  c++  java
  • txt文件分解为固定条数的文件

    #-*- 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
  • 相关阅读:
    课后listview作业
    安卓sql
    activity带数据跳转
    安卓第四周作业
    15周作业
    十三周作业-集合
    十三周上机练习
    12周作业
    linux
    Questions.
  • 原文地址:https://www.cnblogs.com/oneby/p/5454297.html
Copyright © 2011-2022 走看看