Skip to content

Instantly share code, notes, and snippets.

@dmahugh
Created May 3, 2016 04:43
Show Gist options
  • Save dmahugh/4a741bea64f8eac94676cf31124059e4 to your computer and use it in GitHub Desktop.
Save dmahugh/4a741bea64f8eac94676cf31124059e4 to your computer and use it in GitHub Desktop.
enabling Unicode support in VS Code's console
# If you're scanning the file system in Python, you will eventually come across filenames
# that can't be displayed in the VS Code console because they contain characters that
# will raise a UnicodeDecode Error. Opening sys.stdout as shown below fixes this problem.
# this ensures the console will handle Unicode characters
import sys
sys.stdout = open(sys.stdout.fileno(), mode='w', encoding='utf8', buffering=1)
# the following print() statement crashes in the VS Code console window with a
# UnicodeDecodeError if you DON'T set sys.stdout as shown above
print('A few Unicode characters: ® Σ Α Π Φ Ω')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment