python 将一个txt文件数据,按要求分开,写入多个txt文本中

2023-10-13 17:06:11 浏览数 (2)

代码语言:javascript复制
# 读取总txt文件
open_diff = open('diff_match_image.txt', 'r')
diff_line = open_diff.readlines()
 
line_list = []
for line in diff_line:
    line_list.append(line)
# print(line_list)
 
#切分diff
diff_match_split = [line_list[i:i 100] for i in range(0,len(line_list),100)]
 
#将切分的写入多个txt中
for i,j in zip(range(0,13),range(0,13)):
    with open('diff_match%d.txt'% j,'w ') as temp:
        for line in diff_match_split [i]:
            temp.write(line)

0 人点赞