X
X
xSkyFoXx2011-12-01 11:25:27
Python
xSkyFoXx, 2011-12-01 11:25:27

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

2 answer(s)
M
MikhailEdoshin, 2011-12-01
@xSkyFoXx

That is, these are normal lines - print, say, the first one print my_str.replace(' ', '').split('^')[0]and see.

F
ForeverYoung, 2011-12-01
@ForeverYoung

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 question

Ask a Question

731 491 924 answers to any question