-1

I am currently trying to output a csv file with a few European languages like German and Spanish. When I create the file, I need to specify an encoding in order to not get messed up output. I tried iso-8859 and cp1252, but there has to be at least a few characters that are messed up (meaning that they are not from the language). Code:

output = open('output.csv', 'w', newline="", encoding='iso_8859_1')

The input that I give to the file is from OpenAI's API.

Omar Zayed
  • 91
  • 1
  • 10

2 Answers2

1

Just use utf-8:

output = open('output.csv', 'w', newline="", encoding='utf-8')
Damiaan
  • 777
  • 4
  • 11
  • I did. But the problem is that the output becomes more messed up, giving me weird signs. – Omar Zayed Sep 23 '22 at 12:46
  • This is some example output. – Omar Zayed Sep 23 '22 at 12:47
  • @OmarZayed: just set the other editors to UTF-8. All of them should be able to cope with UTF-8 which it is in fact the standard encoding now. On Windows you may want to use UTF-8 with bon so `'utf-8-sig'` as Python encoding string. It mess up other tools. – Giacomo Catenazzi Sep 23 '22 at 12:56
-1

I don´t know if this is valid for german, but its valid for spanish. Try "latin1" in the encoding

Hope it helps

ssanga
  • 335
  • 3
  • 11