如何基于Python按行合并两个txt
作者:yaominghui 时间:2021-03-19 08:24:41
环境python3.6
合并前第一个文件和第二个文件
代码
file1 = open("my.txt","r")
file2 = open("ids.txt","r")
file1_lists =file1.readlines()
file2_lists =file2.readlines()
file3_list = []
file4_list = []
for i in file1_lists:
temp_list = i.split()
file3_list.append(str(temp_list[0]))
# print(len(file3_list))
for i in file2_lists:
temp_list = i.split()
file4_list.append(str(temp_list[0]))
# print(len(file4_list))
main_file = []
for i in range(len(file3_list)):
s=""
s = "".join([file3_list[i],file4_list[i]])
s+="\n"
main_file.append(s)
file3 = open("three.txt","w")
file3.writelines(main_file)
合并后的文件
来源:https://www.cnblogs.com/san357/p/13882638.html
标签:Python,按行,合并,txt
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决pycharm 工具栏Tool中找不到Run manager.py Task的问题
2023-02-26 09:04:31
![](https://img.aspxhome.com/file/2023/2/104892_0s.jpg)
实例演练ASP+XML编程
2007-10-11 13:53:00
Dreamwaver 常见问答解答
2009-07-05 18:51:00
ASP获取当前页面URL地址(带参数)的方法
2010-01-14 19:40:00
Python编写百度贴吧的简单爬虫
2023-12-06 02:17:56
taobao cdn的缓存?
2009-09-19 17:21:00
php bugs代码审计基础详解
2023-06-02 13:49:52
![](https://img.aspxhome.com/file/2023/6/55366_0s.png)
Oracle 分析函数RANK(),ROW_NUMBER(),LAG()等的使用方法
2009-11-05 21:45:00
浅析MySQL数据库授权原则
2009-12-15 09:21:00
PHP网站建设的流程与步骤分享
2023-07-07 00:28:26
Python CategoricalDtype自定义排序实现原理解析
2021-05-31 22:30:32
![](https://img.aspxhome.com/file/2023/7/84107_0s.jpg)
基于Python实现帕累托图的示例详解
2022-06-28 05:48:00
![](https://img.aspxhome.com/file/2023/2/101562_0s.png)
Pycharm远程连接服务器并实现代码同步上传更新功能
2023-09-20 04:44:40
![](https://img.aspxhome.com/file/2023/7/76117_0s.jpg)
Python列表推导式、字典推导式与集合推导式用法实例分析
2022-04-10 10:34:00
使用k8s部署Django项目的方法步骤
2022-12-30 01:59:56
python实现文本文件合并
2022-01-06 04:30:27
Python 函数装饰器详解
2021-11-20 04:34:16
Tensorflow使用支持向量机拟合线性回归
2021-01-20 03:38:42
![](https://img.aspxhome.com/file/2023/7/92517_0s.jpg)
Oracle Index 的三个问题
2010-07-26 12:53:00
python开发之thread实现布朗运动的方法
2021-04-10 00:17:36
![](https://img.aspxhome.com/file/2023/2/92102_0s.png)