欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python讀取分割壓縮TXT文本文件實例

 更新時間:2020年02月14日 13:36:34   作者:子覺  
今天小編就為大家分享一篇Python讀取分割壓縮TXT文本文件實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

廢話不多說,上代碼看吧!

'''
 
為了避免截斷中文字符 
文件要求是 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') 
 
#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文本文件實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論