Python unicode utf-8 || PRINT prints "wąż" correctly, but in a List1 the same "wąż" string is printed as 'w\xc4\x85\xc5\xbc'
Question: I declared the utf-8 encoding and when I `print "wąż"` or other uncommon
characters, terminal properly prints out "wąż".

But when I have a list with a string "wąż" and print the whole list, I get
`'w\xc4\x85\xc5\xbc'`.

The code:

    
    
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    list1 = ['wąż']
    

But when I print the whole list1:

    
    
    >>>print list1
    ['w\xc4\x85\xc5\xbc']
    

When I print list1[0] or simply print the string "wąż", it prints correctly:

    
    
    >>>print list1[0]
    >>>print "wąż"
    wąż
    wąż
    

* * *

_An hour later..._

Okay so I tried to encode the list in utf-8 with `[x.encode('utf-8') for x in
list1]`, but this threw me an Error: _UnicodeDecodeError: 'ascii' codec can't
decode byte 0xc4 in position 1: ordinal not in range(128)._

So I checked my current encoding with the code below, and turns out I had
`ascii`.

    
    
    import sys
    reload(sys)
    print sys.getdefaultencoding()
    

So I change the encoding to `utf-8` with: `sys.setdefaultencoding("utf-8")`
and it properly prints that I have `utf-8` right now.

So again I go with:

`>>>[x.encode('utf-8') for x in list1]`

`>>>print list1`

`['w\xc4\x85\xc5\xbc']`

But it changes nothing. It still refuses to display the correct characters.


Answer: Try this:

    
    
    >> meh = u'wąż'.encode('utf-8')
    
    >> print meh.decode('utf-8')
    wąż
    

So you basically encode/decode the unicode on the basis of a specified
encoding.

Its described well here: <https://docs.python.org/2/howto/unicode.html#the-
unicode-type>

