Default sublime text python build system on windows. The system locale is cp1251 and stdout is cp866 (madness! ), this probably causing problems like
[quote]D:>python test.py
будь проклят тот день когда я сел за интерпретатор этого байткода
D:>python test.py > file.txt
UnicodeEncodeError: ‘ascii’ codec can’t encode characters …][/quote]
I’ve found a solution, perhaps this code should be included in sublime text?
[code]# coding: utf-8
import sys
import codecs
def setup_console(sys_enc=“utf-8”):
“”"
Set sys.defaultencoding to sys_enc
and update stdout/stderr writers to corresponding encoding
For Win32 the OEM console encoding will be used istead of sys_enc
“”"
reload(sys)
try:
if sys.platform.startswith(“win”):
import ctypes
enc = “cp%d” % ctypes.windll.kernel32.GetOEMCP() #TODO: win64/python64 implementation
else:
enc = (sys.stdout.encoding if sys.stdout.isatty() else
sys.stderr.encoding if sys.stderr.isatty() else
sys.getfilesystemencoding() or sys_enc)
sys.setdefaultencoding(sys_enc)
# redefine stdout/stderr in console
if sys.stdout.isatty() and sys.stdout.encoding != enc:
sys.stdout = codecs.getwriter(enc)(sys.stdout, 'replace')
if sys.stderr.isatty() and sys.stderr.encoding != enc:
sys.stderr = codecs.getwriter(enc)(sys.stderr, 'replace')
except:
pass
setup_console()
print u"будь проклят тот день когда я сел за интерпретатор этого байткода"[/code]