Aug-26-2020, 01:04 AM
OK. I could not make csv models to work
and I decided to go the long way.
I wanted to open both files, find matching lines and append the last element of one file to the end of the second file.
For some reason, the code stops after the first match
.
Here is a code:
![Wall Wall](https://python-forum.io/images/smilies/eusa_wall.gif)
I wanted to open both files, find matching lines and append the last element of one file to the end of the second file.
For some reason, the code stops after the first match
![Confused Confused](https://python-forum.io/images/smilies/confused.png)
Here is a code:
import os import re hnd_stat = 'C:/Scripts/file1.txt' cur_stat = 'C:/Scripts/file2.txt' with open (cur_stat,'r+') as cur, open (hnd_stat, 'r') as hnd: for cln in cur : match_cnl = re.findall(r"^[A-Z]{4}\d{5},CELL", cln) if match_cnl : cln_sp = cln.split(",") cln_m = cln_sp[0]+","+cln_sp[1] for hln in hnd : hln_sp = hln.split(",") hln_m = hln_sp[0]+","+hln_sp[1] if hln_m in cln : print ("Appending ",cln+","+hln_sp[2])Could anybody point me how to get around it?