Bonjour

Version Python 3.6
Systeme windows

Je cherche a convertir un fichier Latin-1 vers UTF-8
Lorsque j'exécute ce code les 2 fichiers ont identiques.
Le fichier de sortie reste dans le format latin-1.
Autre point convertion DOS/UNIX UNXI/DoS comment modifier le caractère de fin de ligne pour passe d'un systeme à l'autre

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding: utf-8  
import sys
import os
from Explorateur import explorateur_window
'''
Created on 20 nov. 2017
 
@author: dedalios
'''
 
 
 
if __name__ == '__main__':
 
    open_ok =False    
    nom_fichier_path_in = explorateur_window (".//") # Recherche via explorateur
    if os.path.isfile(nom_fichier_path_in):
 
        # Ouverture du fichier destination
        nom_fichier_in = os.path.basename(nom_fichier_path_in) # Retourne le nom du fichier
        nom_fichier_path = os.path.dirname(nom_fichier_path_in) # Retourne le répertoire complet
        list_nf = os.path.split(nom_fichier_path_in) # Fractionne le chemin d'acc?s. Retourne un tuple
        nom_fichier_out = nom_fichier_path +'//'+'new.' + nom_fichier_in.strip()
 
        with open(nom_fichier_path_in, encoding="Latin-1") as fin, open(nom_fichier_out, 'x', encoding="utf-8") as fout:
            for line in fin:
                fout.write(line)
    pass