-1

I'm developing a cod to automate tables. I'm still at the beginning of what I want to do. Anyway, the cod it creates has to be played in a text file. However, some special characters it cannot read

Ex: ...value='S�O PAULO (CGH)';...

try:
    file = open('codigo.txt', 'w')
    file.writelines(cod)
except FileNotFoundError:
    file = open('codigo.txt', 'w')
    file.writelines(cod)
file.close()

Is there a way to fix it?

Gabriel Edu
  • 628
  • 3
  • 11

1 Answers1

2

Try file = open('file.txt', 'w', encoding='utf-8') (or a different encoding)

For more, see - https://docs.python.org/3/howto/unicode.html

Y.R.
  • 371
  • 1
  • 7