文章来源:淘论文网   发布者: 毕业设计   浏览量: 46



还可以点击去查询以下关键词:
[Python]    [读取]    [分割]    [压缩]    [毕业]    [文本]    [文件]    [方法]    [Python读取分割压缩毕业TXT文本文件方法]   

本文为大家讲解分析用Python来将一个大的txt文件分割成需要的大小k,论文Python读取分割压缩TXT文件的方法代码详解。大文本文件我们可能只需要其中一小部分,这时候就需要来做分割文件的操作,用Python代码也可以很好的完成。

实现文件分割需要用到的python模块方法有Python os模块、struct,具体代码如下:

''' 为了避免截断中文字符 文件要求是 unicode 编码 txt文件另存为对话框下面有下拉框,开题报告,可选存 储编码格式 ''' import os import struct #导入所需python模块方法 filename = str(raw_input('Please enter an old file name: ')) filenamepre = str(raw_input('Please enter an new file name prefix: ')) count = 0 filecount = 0 maxcount = 20 newfilename = repr(filecount) + '.txt' oldfile = open(filename,'rb') # bFirst = True while True: s = oldfile.read(512*8 - 4) if not s: exit() filecount = filecount + 1 newfilename = filenamepre + repr(filecount).zfill(2) + '.txt' newfile = open(newfilename,'wb') if not bFirst: be = 0XFEFF newfile.write(struct.pack('H',be)) newfile.write(s) be = 0X000A000D newfile.write(struct.pack('I',be)) newfile.close() bFirst = False oldfile.close() #文件相关操作切记要关闭

浏览此文章的会员还在关注:gzip python

Python其它文件操作方法相关文章:用Python合并多个文件的方法代码、Python 文件对象常用内建方法、Python遍历文件夹目录与文件操作


这里还有:


还可以点击去查询:
[Python]    [读取]    [分割]    [压缩]    [毕业]    [文本]    [文件]    [方法]    [Python读取分割压缩毕业TXT文本文件方法]   

请扫码加微信 微信号:sj52abcd


下载地址: http://www.taolw.com/down/1892.docx
  • 上一篇:用Python合并多个文件为毕业设计一个文本文件的方法代码
  • 下一篇:用Python实现一个简单的毕业设计线程池模型效果代码分析讲解
  • 资源信息

    格式: docx