Hello.
I using Sublime Text with Python. When I execute my script, the information is displayed in some incomprehensible encoding. My settings are shown in the screenshot. What is the problem? I need Cyrillic output.
Encoding output
Python’s default encoding is utf-8
.
The build system runs python without “shell” argument and thus directly. So you shouldn’t need to specify an ANSI fallback encoding.
Your screenshot looks like the utf-8 output from python is displayed using CP1251 without actually decoding it. In other words, the panel assumes CP1251 while it gets utf-8.
Note: If you want to run more sophisticated scripts with input, you should probably use Terminus package as the build panel is “output-only”. It is normally meant for compiler output.
Thanks for the answer. I commented out fallback enc, but trouble not gone. I have terminus, but for this script I’m interested in the correct display of the Cyrillic.
The issue is caused by ping
printing output with the default DOS code page used by cmd.exe
, which should be cp855
in your case, while python and ST assume utf-8.
An additional print()
statement with cyrillic text will most likely display correct.
So you have two options:
- somehow teach
ping
to return text usingutf-8
. Not sure how to inject achcp 65001
though. - Use custom build system, which specifies
cp855
as encoding for python and output.
Example:
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "cp855",
"env": {"PYTHONIOENCODING": "cp855"},
"windows": {
"cmd": ["py", "-u", "$file"],
},
"variants":
[
{
"name": "Syntax Check",
"cmd": ["python3", "-m", "py_compile", "$file"],
"windows": {
"cmd": ["py", "-m", "py_compile", "$file"],
}
}
]
}