Answer the question
In order to leave comments, you need to log in
Split and Russian strings in Python 2.X
Here is such a short example:
Gives such a terrible result:
Tell me, please, how to overcome this? How to return to normal strings after split?
PS
The encoding of the script file is utf8
# -*- coding: utf-8 -*-
my_str = u'Строка ^ с ^ разделителями!'
print my_str.replace(' ', '')
print my_str.replace(' ', '').split('^')
Строка^с^разделителями!
[u'\u0421\u0442\u0440\u043e\u043a\u0430 ', u' \u0441 ', u' \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438!']
Answer the question
In order to leave comments, you need to log in
That is, these are normal lines - print, say, the first one print my_str.replace(' ', '').split('^')[0]
and see.
Because printing a list prints repr() from its elements.
see Container's __str__ uses contained objects' __repr__
For example, you could type something like this:
Some more info here: see Since this question involves a lot of confusing unicode stuff, I thought I'd offer an analysis of what was going on here.
for item in lst: print item
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question