Найти - Пользователи
Полная версия: Unicode -> ASCII не могу разобраться
Начало » Python для новичков » Unicode -> ASCII не могу разобраться
1
Moroznui
Делаю по HOW-TO: http://docs.python.org/howto/unicode.html#the-unicode-type
>>> u='ule/\xd0\xad_041.xls'
>>> print u
ule/Э_041.xls
>>> u.encode('ascii', 'xmlcharrefreplace')
Traceback (most recent call last):
File "<console>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 4: ordinal not in range(128)
Что не так с руками?
Версия python 2.6
PooH
В u у вас не unicode, а байтовая строка. Питон сначала пытается привести ее к unicode используя кодек ascii и обламывается. Обратите внимание на ошибку UnicodeDecodeError.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB