Set to encode the standard system output file in the UTF-8 document:
import sys import codecs sys.stdout = codecs.getwriter( "utf-8" )( sys.stdout.detach() ) print( "1" ) print( "áéíóúý âêîôû äëïöü àèìòù ãñõ" ) print( "2" )
To automatically apply UTF-8 encoded output to all documents, use the previous method as the built-in command in your Python.sublime-build file.
After the encoding has been set, your document is loaded via exec inside the built-in command .
{ "cmd": [ "python", "-u", "-c", "import sys; import codecs; sys.stdout = codecs.getwriter( 'utf-8' )( sys.stdout.detach() ); exec( compile( open( r'$file', 'rb' ).read(), r'$file', 'exec'), globals(), locals() )" ], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", "variants": [ { "name": "Syntax Check", "shell_cmd": "python -m py_compile \"${file}\"", } ] }
Tip. Use PackageResourceViewer to create a copy of Python.sublime-build user
Tested with Sublime Text 3 (stable channel, build 3103) and Python 3.4.3
Sources:
How to set sys.stdout encoding in Python 3?
Alternative execfile in Python 3?
Enteleform
source share