Search code examples
pythonutf-8encode

How do I get Cyrillic in the output, Python?


how do I get Cyrillic instead of u'...

the code is like this

def openfile(filename):
    with codecs.open(filename, encoding="utf-8") as F:
        raw = F.read()
do stuff...
print some_text

prints

>>>[u'.', u',', u':', u'\u0432', u'<', u'>', u'(', u')', u'\u0437', u'\u0456']


Solution

  • It looks like some_text is a list of unicode objects. When you print such a list, it prints the reprs of the elements inside the list. So instead try:

    print(u''.join(some_text))
    

    The join method concatenates the elements of some_text, with an empty space, u'', in between the elements. The result is one unicode object.