It produces mojibake because '' is a bytestring literal in Python 2 (unless using from __future__ import unicode_literals ). You print utf-8 bytes (source code encoding) to a Windows console that uses some other character encoding (the encoding is different if you see mojibake):
>>> print(u''.encode('utf-8').decode('cp866')) β¨β€β€β€β¨ββ¨ββ¨β£
The solution is to print Unicode instead as @JBernardo suggested :
#!/usr/bin/env python
It works if the console encoding supports Cyrillic letters, for example, if it is cp866 .
If you want to redirect the output to a file; you can use the PYTHONIOENCODING environment PYTHONIOENCODING to set the character encoding used by Python for I / O:
Z:\> set PYTHONIOENCODING=utf-8 Z:\> python your_script.py > output.utf-8.txt
If you want to print Unicode characters that cannot be represented using console coding ( OEM code page ), then you can install win-unicode-console Python package :
Z:\> py -m pip install win_unicode_console Z:\> py -m run your_script.py
source share