This question has already been answered:
Good day. I try to write in the command print ('any text with Russian letters') and actually nothing happens. I write the text in English, everything works. Can you tell me how to fix it?
Language - Python
This question has already been answered:
Good day. I try to write in the command print ('any text with Russian letters') and actually nothing happens. I write the text in English, everything works. Can you tell me how to fix it?
Language - Python
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
If you have python2, then you have all the default strings - byte. Consequently, when you try to output you get an error.
In order to convert a byte string to unicode, you must either add an explicit type conversion (eg print (unicode (my_string))), or, if the string is specified directly in the file or interpreter, tell python that it is a unicode string by adding the character 'u 'before opening quotation mark, for example, print (u' string ')
To solve this problem in recent versions of python 2 (in particular in 2.7), Unicode strings from python 3 are ported. In order for all the lines in the .py file to become Unicode, you need to add at the top of the file
from __future__ import unicode_literals If you are trying to do this in a .py file, then you must specify the encoding of this file as the first line, as python2 considers this ascii file. This can be done by adding the line
# -*- coding: utf-8 -*- at the beginning of the file.
In python 3, all unicode strings and such problems usually do not occur.
Updated 2
Correct the file so that it looks like this.
# -*- coding: utf-8 -*- print('ку-ку') Updated 3
coding: utf-8 only tells python that the contents of the file should be interpreted as utf-8. Check in your editor if this is true. It seems to me if the solution above does not help, then the problem is precisely this - your editor saves in windows-1251 encoding. We need to find where it is configured and changed.
Source: https://ru.stackoverflow.com/questions/540467/
All Articles
.py) using utf-8 encoding, and not cp1251 or cp866. - jfs