Python讀取分割壓縮TXT文本文件實(shí)例
更新時(shí)間:2020年02月14日 13:36:34 作者:子覺
今天小編就為大家分享一篇Python讀取分割壓縮TXT文本文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧
廢話不多說,上代碼看吧!
''' 為了避免截?cái)嘀形淖址? 文件要求是 unicode 編碼 txt文件另存為對(duì)話框下面有下拉框,可選存 儲(chǔ)編碼格式 ''' import os import struct #導(dǎo)入所需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') #www.iplaypy.com 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() #文件相關(guān)操作切記要關(guān)閉
以上這篇Python讀取分割壓縮TXT文本文件實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章

python讀取.mat文件的數(shù)據(jù)及實(shí)例代碼
這篇文章主要介紹了python讀取.mat文件的數(shù)據(jù)的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
2019-07-07 
Python實(shí)現(xiàn)灰色關(guān)聯(lián)分析與結(jié)果可視化的詳細(xì)代碼
今天小編通過代碼以灰色色系為例給大家介紹Python灰色關(guān)聯(lián)分析實(shí)現(xiàn)方法,灰色關(guān)聯(lián)度分析對(duì)于一個(gè)系統(tǒng)發(fā)展變化態(tài)勢(shì)提供了量化的度量,非常適合動(dòng)態(tài)歷程分析,感興趣的朋友一起看看吧
2022-03-03 
用python基于appium模塊開發(fā)一個(gè)自動(dòng)收取能量的小助手
大家都有了解過螞蟻森林吧,本篇文章帶給你自動(dòng)收取螞蟻森林能量的思路與方法,基于appium模塊開發(fā)一個(gè)自動(dòng)收取能量的小助手,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的價(jià)值
2021-09-09