Visual Studio utf-8 error

Asked

Viewed 466 times

2

I tried to use Visual Studio along with the tools to Python, but when I put: print("Hello World") and grip F5 it runs smoothly.

But when I put: print("olá") he gives the following error:

File "C:\Users\.... path .....\PythonApplication1\PythonApplication1.py", line 1
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe1 in position 0:
 unexpected end of data
Press any key to continue . . .

I’d like to know how to solve!

  • 2

    You saved the code in Ansi/Win-1252 instead of UTF-8. Check the encoding used in the editor save options.

  • Thank you very much, my friend!

1 answer

1

Try this:

#coding: UTF-8
print('olá')

Depending on the Python version, the encoding used should be specified if you want to use special characters. If it doesn’t work, try this too:

#coding: latin-1
print('olá')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.