最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Python通过分隔符分割文件后按特定次序重新组合操作代码
时间:2022-06-25 02:05:38 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下Python通过分隔符分割文件后按特定次序重新组合操作代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
代码如下:
#-*-encoding:utf-8-*-
import os, sys, time, datetime, glob
fo1 = open("C:/Users/Administrator/Desktop/areainfo.txt", "w")
fo2 = open("C:/Users/Administrator/Desktop/personinfo.txt", "w")
for root, dirs, files, in os.walk("E:/test", topdown=False):
for name in files:
file_name = os.path.join(root,name)
if os.path.splitext(file_name)[1] == '.txt':
print(file_name)
with open(file_name) as a_file:
for data in a_file.readlines():
str2=[]
str4=[]
for i in [0, 1, 2, 3, 7]:
str2.append(data.split('||~||')[i])
fo1.write("||~||".join(str2)+"n")
for i in [4, 5, 6, 7, 8, 9, 10, 11]:
str4.append(data.split('||~||')[i])
fo2.write("||~||".join(str4)+"n")
fo1.close()
fo2.close()
相关文章
- 奔奔王国怎么升阶 建筑英雄宠物升阶方法介绍 12-30
- 奔奔王国怎么找到攻击的人 找到攻击玩家的方法 12-30
- 奔奔王国游戏官网入口在哪 2025年最新官网地址汇总 12-30
- 奔奔王国vip礼包码有哪些 2025年12月vip礼包码汇总 12-30
- 奔奔王国兑换码有什么 2025年12月最新可用兑换码汇总 12-30
- 菜鸡梦想家是什么类型的游戏 游戏类型及核心玩法介绍 12-30