1

I'm using Visual Studio Code, Python 3.5.2, Windows 10

print("£")

produces 2 symbols that I'm not familiar with.

input("Enter pound sign: ") -> £

produces the error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 0: invalid start byte

The above examples work perfectly using Python IDLE. I've tried changing the Encoding within Visual Studio Code with no success.

I've used Python 3.5.2 for some time now I never have this problem using Sublime Text 3.

Advice on solving this issue would be much appreciated.

1 Answer 1

3

This seems to be an issue with the Code Runner plugin of VS Code. A workaround is to run the code in the terminal. Add the following lines to the User or Workspace Settings file:

"code-runner.runInTerminal": false

This works on a Mac, I'm not sure about Windows.

Generally speaking the problem is that the default encoding used to print on the console doesn't support UTF-8. You can check the default encoding used by executing the following:

import sys
print(sys.stdout.encoding)

When I use the Code Runner plugin with the default configuration settings this value is US-ASCII, but when run it using terminal it is UTF-8.

Unfortunately I don't know how to change the default encoding for the Code Runner plugin.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.