import csv def correction_csv(nomdufichier): csv_corrige = '' with open(f'{nomdufichier}.csv', newline='', encoding='utf-8') as csvfile: appariement_0 = csv.reader(csvfile, delimiter=' ') for row in appariement_0: ligne_brute =' '.join(str(elem) for elem in row) ligne_brute = ligne_brute.replace("ê", "ê") ligne_brute = ligne_brute.replace("é", "é") ligne_brute = ligne_brute.replace('Ã\xa0', "à") ligne_brute = ligne_brute.replace('è', "è") ligne_brute = ligne_brute.replace('ô', "ô") ligne_brute = ligne_brute.replace('û', "û") ligne_brute = ligne_brute.replace('î', "î") ligne_brute = ligne_brute.replace('â', "â") ligne_brute = ligne_brute.replace('É', 'É') ligne_brute = ligne_brute.replace('ç', 'ç') csv_corrige = csv_corrige + ligne_brute + '\n' print(ligne_brute) fichier_txt=open(f"{nomdufichier}_correct_bis.csv","w", encoding='utf-8') fichier_txt.write(csv_corrige) fichier_txt.close() # correction_csv('emissions') # correction_csv('etablissements') #correction_csv('Prelevements') #correction_csv('Prod_dechets_dangereux') # correction_csv('Prod_dechets_non_dangereux') # correction_csv('Trait_dechets_dangereux') # correction_csv('Trait_dechets_non_dangereux') # correction_csv('tr_nap') # correction_csv('tr_naf') correction_csv('tr_code_effectif') # correction_csv('te_siren_adresse') # correction_csv('te_siren_admin') # def remplacement_carac(nom_str): # nom_str = nom_str.replace("ê", "ê") # nom_str = nom_str.replace("é", "é") # nom_str = nom_str.replace('Ã\xa0', "à") # nom_str = nom_str.replace('è', "è") # nom_str = nom_str.replace('ô', "ô") # nom_str = nom_str.replace('û', "û") # nom_str = nom_str.replace('î', "î") # nom_str = nom_str.replace('â', "â") # nom_str = nom_str.replace('É', 'É')