请把你的TXT文件内容截图发出来看看
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/91ef76c6a7efce1bc2b6ddd0a151f3deb48f650e?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追答# 读取txt文件
# with open('txt.txt', "r") as f:
# txt = f.read()
# 假设txt文件内容为:
txt = '''
abc1//abc2//abc3//
abc4//abc5//abc6
'''
arr = txt.split('//') # 用//分割内容
print(arr) # 得到: ['\nabc1', 'abc2', 'abc3', '\nabc4', 'abc5', 'abc6\n']
for i, v in enumerate(arr): # 遍历arr 每个元素生成一个文件
if v == '': continue # 跳过内容为空的
with open(str(i) + '.txt', 'w') as f:
f.write(v)
# 结果生成 0.txt 1.txt 等 6个文件
本回答被网友采纳