Python UTF8

Perhaps the eternal question, but still can't keep up with him. How to make pyhton to understand urf8

In the beginning all there for that
# -*- coding: utf-8 -*-<br / > import sys<br> reload(sys)<br> sys.setdefaultencoding('utf-8')

So, if you write:
>submit = "Login"<br> >print submit<br> Log

it's all right

But if the code here like this
>login_form = [<br> ('log', 'admin')<br> ('login', submit)]<br> >print login_form<br> [('log', 'admin'), ('login', '\xd0\x92\xd0\xbe\xd0\xb9\xd1\x82\xd0\part no xb8')

How to deal with this scourge?
October 8th 19 at 03:09
4 answers
October 8th 19 at 03:11
Start with reading the book.

u"Enter"
By the way, after this you have the word "Log" in any of the Unicode output it will still be codes because the print objects for which you have not defined method will display the internal representation. - Erik_Muller76 commented on October 8th 19 at 03:14
But sys.setdefaultencoding('utf-8') this sets or not? - ottis1 commented on October 8th 19 at 03:17
> method output will output the internal representation

Here for you is the key. Read about "repr". - arielle_OReilly commented on October 8th 19 at 03:20
> But sys.setdefaultencoding('utf-8') this sets or not?
So read the documentation:
> Set the current default string encoding used by the Unicode implementation.
Unicode implementeren. You specify a string without a prefix u, i.e. not as unikalnoy. - Erik_Muller76 commented on October 8th 19 at 03:23
>Unicode implementeren. You specify a string without a prefix u, i.e. not as unikalnoy.
if u ask using' the same effect, repr too, has not led to success yet... still experimenting - ottis1 commented on October 8th 19 at 03:26
> if you ask through u' the effect is the same
I immediately wrote, and will be internally represented. Want normal output — tell Python how to display your data. For example:
"\n".join("%s: %s" % field for field in login_form) - Erik_Muller76 commented on October 8th 19 at 03:29
>otitis normal the conclusion — tell Python how to display your data.
@homm, thanks for the reply, really so everyone can see in the right encoding - ottis1 commented on October 8th 19 at 03:32
October 8th 19 at 03:13
the version of Python depends. In the third and so everything should be in Unicode, and 2.7 in the long begin all your files, this title:

# -*- coding: utf-8 -*-<br / > from __future__ import unicode_literals<br>

problems with Unicode are not watching.

PS: I May not understand correctly what the problem is — then you will be asked to explain.
Yes like understand correctly, the problem is when the variable is in the object, then utf is not displayed. but the answer @homm'a help, about "\n".join("%s: %s" % field for field in login_form), although still have questions... - Erik_Muller76 commented on October 8th 19 at 03:16
October 8th 19 at 03:15
It's just so written out to the console. The encoding remains the same (ie in the form in which You see string in the list). The trick here is that while print this string (print "Enter") translates to "user readable" format, and simple print on the object, this does not translate.
docs.python.org/howto/unicode.html - Erik_Muller76 commented on October 8th 19 at 03:18
Thanks for the explanation. Really the way it is. It remains to find a solution how to bring him to readable view of the object. After all .decode(utf8) and unicode(string,'utf8) do not help... - ottis1 commented on October 8th 19 at 03:21
October 8th 19 at 03:17
And database all the tables and columns to utf-8 but in latin1?

Find more questions by tags PythonUnicode