Python读取分割压缩TXT文本文件实例
废话不多说,上代码看吧!
'''
为了避免截断中文字符
文件要求是unicode编码
txt文件另存为对话框下面有下拉框,可选存
储编码格式
'''
importos
importstruct
#导入所需python模块方法
filename=str(raw_input("Pleaseenteranoldfilename:"))
filenamepre=str(raw_input("Pleaseenterannewfilenameprefix:"))
count=0
filecount=0
maxcount=20
newfilename=repr(filecount)+'.txt'
oldfile=open(filename,'rb')
#www.iplaypy.com
bFirst=True
whileTrue:
s=oldfile.read(512*8-4)
ifnots:
exit()
filecount=filecount+1
newfilename=filenamepre+repr(filecount).zfill(2)+'.txt'
newfile=open(newfilename,'wb')
ifnotbFirst:
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()
#文件相关操作切记要关闭
以上这篇Python读取分割压缩TXT文本文件实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。
热门推荐
8 小托班祝福语简短
10 毕业谢谢老师祝福语简短
11 相亲结束的祝福语简短
12 巧克力情侣祝福语大全简短
13 爸妈对宝宝祝福语简短
14 2026腊八简短祝福语
15 周六早晨祝福语简短
16 侄儿高考试祝福语简短
17 关于旅游的简短祝福语
18 送别的祝福语朋友简短