I'm losing my mind here. I've read and tried so much things that I'm totally lost. I don't usually use Python, and I'm trying to update a code. Before, csv files did not contains any specials characters (like "é"...) and now it does. The actual code returns the exception UnicodeEncodeError :
try:
self.FichierE = codecs.open(self.CheminFichierE,"r", "utf-8")
self.ReaderFichierE = csv.reader(self.FichierE, delimiter=';')
except IOError:
self.TextCtrl.AppendText(u"Fichier E n'a pas été trouvé")
return
try:
DataFichierE = [ligne for ligne in self.ReaderFichierE]
except UnicodeDecodeError:
self.TextCtrl.AppendText(self.NomFichierE+ u" n'est pas lisible")
return
except UnicodeEncodeError:
self.TextCtrl.AppendText(self.NomFichierE+ u" n'est pas lisible (ASCII)")
return
I've tried so many things, I'll just put the last thing I did (and that I thought it should work) :
try:
DataFichierE = []
for utf8_row in self.ReaderFichierE:
unicode_row = [x.decode('utf8') for x in utf8_row]
DataFichierE.append(unicode_row)
except UnicodeDecodeError:
self.TextCtrl.AppendText(self.NomFichierE+ u" n'est pas lisible")
return
except UnicodeEncodeError:
self.TextCtrl.AppendText(self.NomFichierE+ u" n'est pas lisible (ASCII)")
return
Any help will be much appreciated !