Answer the question
In order to leave comments, you need to log in
How to change the encoding only if necessary?
Cycle comes a huge number of rows
Most come in the normal coding ,
but some in the form of "RЎS,SЂRѕRoS,RμR" SЊSЃS,RІRѕ RґRμSЂRμRІSЏRЅRЅS <C ... RґRѕRјRѕRІ Röhr · P ± SЂSѓSЃR ° RїRѕRґ RєR "SЋS ‡, RіRѕS,RѕRІS <Rμ RґRμSЂRμRІSЏRЅRЅS <Rμ RґRѕRјR ° РІ РњРѕСЃРєРІРµ"
In order for this line to take a normal form, you need:
I do such actions with a line of this kind - and it becomes normal.
The problem is that you need to somehow determine in the loop whether it is the right kind or not ... If you do such actions with each line, then most (which were normal) will become scribbles ... name = title.decode('utf-8').encode('cp1251')
Answer the question
In order to leave comments, you need to log in
try:
win_name = unicode(title.encode('cp1251')) #если title нормального вида, эта строка вызовет исключение
name = title.decode('utf-8').encode('cp1251') #если исключения нет, кодируем
except UnicodeDecodeError: #если исключение есть - оставляем
name = title
except UnicodeEncodeError:
name = title
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question