【python读取TXT】读取两个TXT文档并拼接为一个再保存为TXT

本文介绍了如何使用Python读取两个TXT文档,进行内容处理后,将结果拼接并保存为新的TXT文件。示例中展示了处理和拼接的具体代码流程。
摘要由CSDN通过智能技术生成
python很容易实现一些小功能,这次我想要读取两个txt文档里的数据,并把他们其中的一部分内容修改之后,再保存为一个txt文档导出,因为数据很多,导入的两个txt文档的数据行数是一样的。
程序的流程是,把两个txt文档导入到python里,再把他们拼在一次,最后导出。
需要处理的两个txt文档的数据如下:
new.txt:
200:100,0,100,0,255,0,0,heart|50,87,123,0,255,0,0,heart|-50,87,123,0,255,0,0,heart|-100,0,100,0,255,0,0,heart|-50,-87,77,0,255,0,0,heart|50,-87,77,0,255,0,0,heart
200:99,13,100,0,255,0,0,heart|39,92,123,0,255,0,0,heart|-61,79,123,0,255,0,0,heart|-99,-13,100,0,255,0,0,heart|-39,-92,77,0,255,0,0,heart|61,-79,77,0,255,0,0,heart
200:97,25,100,0,255,0,0,heart|26,96,123,0,255,0,0,heart|-70,71,123,0,255,0,0,heart|-97,-25,100,0,255,0,0,heart|-26,-96,77,0,255,0,0,heart|70,-71,77,0,255,0,0,heart
200:93,38,100,0,255,0,0,heart|14,99,123,0,255,0,0,heart|-79,62,123,0,255,0,0,heart|-93,-38,100,0,255,0,0,heart|-14,-99,77,0,255,0,0,heart|79,-62,77,0,255,0,0,heart
200:87,49,100,0,255,0,0,heart|1,100,123,0,255,0,0,heart|-86,51,123,0,255,0,0,heart|-87,-49,100,0,255,0,0,heart|-1,-100,77,0,255,0,0,heart|86,-51,77,0,255,0,0,heart
200:80,60,100,0,255,0,0,heart|-12,99,123,0,255,0,0,heart|-92,39,123,0,255,0,0,heart|-80,-60,100,0,255,0,0,heart|12,-99,77,0,255,0,0,heart|92,-39,77,0,255,0,0,heart
200:72,70,100,0,255,0,0,heart|-24,97,123,0,255,0,0,heart|-96,27,123,0,255,0,0,heart|-72,-70,100,0,255,0,0,heart|24,-97,77,0,255,0,0,heart|96,-27,77,0,255,0,0,heart
200:62,78,100,0,255,0,0,heart|-37,93,123,0,255,0,0,heart|-99,15,123,0,255,0,0,heart|-62,-78,100,0,255,0,0,heart|37,-93,77,0,255,0,0,heart|99,-15,77,0,255,0,0,heart
200:52,86,100,0,255,0,0,heart|-48,88,123,0,255,0,0,heart|-100,2,123,0,255,0,0,heart|-52,-86,100,0,255,0,0,heart|48,-88,77,0,255,0,0,heart|100,-2,77,0,255,0,0,heart
200:40,91,100,0,255,0,0,heart|-59,81,123,0,255,0,0,heart|-99,-11,123,0,255,0,0,heart|-40,-91,100,0,255,0,0,heart|59,-81,77,0,255,0,0,heart|99,11,77,0,255,0,0,heart
200:28,96,100,0,255,0,0,heart|-69,73,123,0,255,0,0,heart|-97,-23,123,0,255,0,0,heart|-28,-96,100,0,255,0,0,heart|69,-73,77,0,255,0,0,heart|97,23,77,0,255,0,0,heart
200:16,99,100,0,255,0,0,heart|-78,63,123,0,255,0,0,heart|-93,-36,123,0,255,0,0,heart|-16,-99,100,0,255,0,0,heart|78,-63,77,0,255,0,0,heart|93,36,77,0,255,0,0,heart
200:3,100,100,0,255,0,0,heart|-85,53,123,0,255,0,0,heart|-88,-47,123,0,255,0,0,heart|-3,-100,100,0,255,0,0,heart|85,-53,77,0,255,0,0,heart|88,47,77,0,255,0,0,heart
200:-10,100,100,0,255,0,0,heart|-91,41,123,0,255,0,0,heart|-81,-58,123,0,255,0,0,heart|10,-100,100,0,255,0,0,heart|91,-41,77,0,255,0,0,heart|81,58,77,0,255,0,0,heart
200:-22,97,100,0,255,0,0,heart|-96,29,123,0,255,0,0,heart|-73,-68,123,0,255,0,0,heart|22,-97,100,0,255,0,0,heart|96,-29,77,0,255,0,0,heart|73,68,77,0,255,0,0,heart
200:-35,94,100,0,255,0,0,heart|-99,17,123,0,255,0,0,heart|-64,-77,123,0,255,0,0,heart|35,-94,100,0,255,0,0,heart|99,-17,77,0,255,0,0,heart|64,77,77,0,255,0,0,heart
200:-46,89,100,0,255,0,0,heart|-100,4,123,0,255,0,0,heart|-54,-84,123,0,255,0,0,heart|46,-89,100,0,255,0,0,heart|100,-4,77,0,255,0,0,heart|54,84,77,0,255,0,0,heart
200:-57,82,100,0,255,0,0,heart|-100,-9,123,0,255,0,0,heart|-42,-91,123,0,255,0,0,heart|57,-82,100,0,255,0,0,heart|100,9,77,0,255,0,0,heart|42,91,77,0,255,0,0,heart
200:-67,74,100,0,255,0,0,heart|-98,-21,123,0,255,0,0,heart|-30,-95,123,0,255,0,0,heart|67,-74,100,0,255,0,0,heart|98,21,77,0,255,0,0,heart|30,95,77,0,255,0,0,heart
200:-76,65,100,0,255,
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值