手机
当前位置:查字典教程网 >脚本专栏 >python >用python分割TXT文件成4K的TXT文件
用python分割TXT文件成4K的TXT文件
摘要:复制代码代码如下:#############################为了避免截断中文字符##文件要求是unicode编码##txt文...

复制代码 代码如下:

##########################

# #

# 为了避免截断中文字符 #

# 文件要求是 unicode 编码 #

# txt文件另存为对话框下面有下拉框,可选存 #

# 储编码格式 #

# #

##########################

import os

import struct

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()

【用python分割TXT文件成4K的TXT文件】相关文章:

Python 文件读写操作实例详解

python中的sort方法使用详解

Python修改Excel数据的实例代码

python读取html中指定元素生成excle文件示例

python和pyqt实现360的CLable控件

Python读写Excel文件的实例

通过python下载FTP上的文件夹的实现代码

python 文件与目录操作

python 中文字符串的处理实现代码

使用python统计文件行数示例分享

精品推荐
分类导航