(Feb-08-2019, 06:19 PM)buran Wrote: pfile = 'processed.txt' # processed lines
infile = 'source_file.txt' # source file
with open(infile, 'r') as inf, open(pfile, 'a+') as pf:
pf.seek(0)
processed_lines = set([line.strip() for line in pf])
for line in inf:
query = line.strip()
if query not in processed_lines: # skip if line in processed lines
# process query here
pf.write(line) # save to processed lines
That is one elegant solution. Thank you.
Two questions:
1) Technically, my function should go right after "Query = line.strip()", correct?
2) This sees which lines are processed and copies those to another file. But how can I delete it from the original file? I think I should set the "r" to "r+", then I should either use writelines() or truncate(). Could you show me that code as well?
And listen I appreciate all the hard work you've done for me. These things must be like a breeze to you but that doesn't diminish your efforts.
If there is anyway I could repay you, please let me know