zoukankan      html  css  js  c++  java
  • 大文件不断行切割

    #! /usr/bin/python
    #! -*- coding:utf-8 -*-
    import os
    def SplitFile(cnt):
      path='e:data'
      filename=path+'\qunti_deal.txt'
      os.chdir(path)
      i=0
      n=0
      size=os.path.getsize(filename)/1024/cnt
      print size
      temp = open(filename+'.part'+str(i),'w')
      f=open(filename,'r')
      while True:
        buf = f.read(1024)
        if buf=='':
          print filename+'.part'+str(i)+';'
          temp.close()
          f.close()
          return
        n+=1
        if n==size:
          t=buf.rfind('
    ')+1
          temp.write(buf[:t])
          n=0
          print filename+'.part'+str(i)+';'
          i+=1
          temp.close()
          temp=open(filename+'.part'+str(i),'w')
          temp.write(buf[t:])
          continue
        temp.write(buf)
    if __name__=='__main__':
    	SplitFile(int(raw_input('#files:')))

  • 相关阅读:
    Java的特性和优势
    MyBatis
    SpringBoot简介
    Liunx
    MySql简介与入门
    Volatile
    MySQL简介
    Redis
    Spring IoC
    什么是springboot
  • 原文地址:https://www.cnblogs.com/mfmdaoyou/p/6848250.html
Copyright © 2011-2022 走看看