Last active
August 29, 2015 14:05
-
-
Save IQAndreas/c6982809b0f8b269e6d8 to your computer and use it in GitHub Desktop.
Get the encoding of the console the script is currently running in (plus a few other lines for debugging)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys, locale; | |
print(sys.stdout.encoding); | |
print(locale.getpreferredencoding()); | |
# http://www.macfreek.nl/memory/Encoding_of_Python_stdout#StreamWriter_Wrapper_around_Stdout | |
if sys.stdout.encoding != 'UTF-8': | |
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') | |
if sys.stderr.encoding != 'UTF-8': | |
sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') | |
print(u"\u201C" + "Hello world!" + u"\u201D") | |
print("\u201CHello world!\u201D") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment