Answer the question
In order to leave comments, you need to log in
Python and UTF8
Perhaps the eternal question, but still I can not cope with it. How to make pyhton understand urf8
In the beginning, everything is there for this And so, if we write:
everything is right here But if the code is like this
How to deal with this misfortune?
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
>submit = "Войти"
>print submit
Войти
>login_form = [
('log', 'admin'),
('login', submit)]
>print login_form
[('log', 'admin'), ('login', '\xd0\x92\xd0\xbe\xd0\xb9\xd1\x82\xd0\xb8')
Answer the question
In order to leave comments, you need to log in
depends on the version of python. In the third, everything should be in unicode anyway, and in 2.7 I have long started all my files with this header:
I don’t see any problems with unicode.
PS: Perhaps I did not understand correctly what the problem is - then I will ask you to explain.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
It's just written to the console. The encoding remained the same (that is, in the form in which you see the string in the sheet). The joke here is that during the print, this string (print “Enter”) is translated into a “user-readable” format, and a simple print over an object does not.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question