Last active
September 22, 2018 07:47
-
-
Save dwoz/74446025830c6004479d5a22593e4c5e to your computer and use it in GitHub Desktop.
Test Setting Codepage from Current Process.
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
#!python | |
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals, print_function | |
import win32console | |
import os | |
import sys | |
import codecs | |
import sys | |
console_codepage = win32console.GetConsoleCP() | |
console_output_codepage = win32console.GetConsoleOutputCP() | |
try: | |
sys.stdout.flush() | |
win32console.SetConsoleCP(65001) | |
win32console.SetConsoleOutputCP(65001) | |
if sys.version_info[0] >= 3: | |
sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) | |
else: | |
sys.stdout.close() | |
sys.stdout = os.fdopen(1, 'wb') | |
sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | |
unicodestr = 'äöü€' | |
print(unicodestr) | |
print(repr(unicodestr)) | |
finally: | |
sys.stdout.flush() | |
win32console.SetConsoleCP(console_codepage) | |
win32console.SetConsoleOutputCP(console_output_codepage) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment