I have to replace strings like this one:
-- 1234,BUCARAMANGA,"KM 15 VIA QUE CONDUCE AGUACHICA-BUCARAMANGA, CORREGIMIENTO EL JUNCAL"
and turn them into strings like this one (removing the comma in between the quotation amrks)
-- 1234,BUCARAMANGA,"KM 15 VIA QUE CONDUCE AGUACHICA-BUCARAMANGA CORREGIMIENTO EL JUNCAL"
I'm using this code:
f1 = open('FACMES.txt', 'r',encoding ='utf-8')
f2 = open('FACMES_2.txt', 'w',encoding ='utf-8')
checkWords = ("KM 15 VIA QUE CONDUCE AGUACHICA-BUCARAMANGA, CORREGIMIENTO EL JUNCAL","COOPERATIVA TECNICOS, TECNOLOGOS PROFESIONALES COOTETECPRO","3 KMS DE LA VÍA FLORENCIA - PAUJIL, DE LA Y A MANO DERECHA DELANTE PTO ARANGO")
repWords = ("KM 15 VIA QUE CONDUCE AGUACHICA-BUCARAMANGA CORREGIMIENTO EL JUNCAL","COOPERATIVA TECNICOS TECNOLOGOS PROFESIONALES COOTETECPRO","3 KMS DE LA VÍA FLORENCIA - PAUJIL DE LA Y A MANO DERECHA DELANTE PTO ARANGO")
for line in f1:
for check, rep in zip(checkWords, repWords):
line = line.replace(check, rep)
f2.write(line)
f1.close()
f2.close()
Is there some way to replace the comma only when the comma is between double quotes and other characters?