mardi 2 juillet 2019

TypeError: 'in

I am comparing 2 files and remove the duplicates from the second file. But throwing error

2 files. Need to add one number at last of first line and append into file2.txt. But if the modified part is already there then file2 remain untouched

import re
import sys
file1 = sys.argv[1]
file2 = sys.argv[2]
rx = r'(?<=:)(\d*)$'
with open(file1,'r') as fh:
    fh_n = fh.read()
    with open(file2, 'a+') as fw:
        if fw not in file2:  #error part
            fw.write(re.sub(rx , lambda x: str(int(x.group(0)) + 1) if len(x.group(1)) else "0", fh_n, 1, re.M))

file1.txt

python 2.7:
  Java 1.8:

python test.py file1.txt file2.txt

Expected Out even after so many execution

 python 2.7:0
      Java 1.8:

Aucun commentaire:

Enregistrer un commentaire