[问题] File1内容跳一行再加File2内容

楼主: Dong0129 (阿东跟上面讲的情况一样b)   2015-04-17 10:45:09
请问各位版友,
我有两个档案,
File1: File2:
1 5
2 6
3 7
4 8
要合并成:
File3:
1 5
2 6
3 7
4 8
目前的code:
rfd1=open("file1","r")
rfd2=open("file2","r")
wfd=open("file3","w")
for i in rfd1:
if i[-1]=='\n':
i=[0:-1]
wfd.write(i)
for i in rfd2:
wfd.write('\t'+i)
break
rfd1.close()
rfd2.close()
wfd.close()
目前想出来也可用的程式码如上,
但在思考是否有更好更短的写法呢??
还算是python初学者...所以写的不够好请见谅!!
作者: alibuda174 (阿哩不达)   2015-04-17 11:06:00
for x in zip(rfd1, rfd2):f3.write(x[0].rstrip('\n') + '\t' + x[1])抱歉 f3改成wfd

Links booklink

Contact Us: admin [ a t ] ucptt.com