B
B
BFox2012-02-20 14:13:06
Python
BFox, 2012-02-20 14:13:06

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

4 answer(s)
H
homm, 2012-02-20
@homm

Start by reading a book.
u"Войти"

X
xenolog, 2012-02-20
@xenolog

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

K
Konstantin, 2012-02-20
@Norraxx

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.

E
Egor Kazantsev, 2014-01-04
@saintbyte

And at base all tables and columns in utf-8 and in latin1?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question