当我尝试转换Unicode时:
a = u"Тест"
转化为字符串:
str(a)
I got this error:
'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
我需要str(a)输出结果:
>> str(a)
>> 'Тест'
当我尝试转换Unicode时:
a = u"Тест"
转化为字符串:
str(a)
I got this error:
'ascii' codec can't encode characters in position 0-3: ordinal not in range(128)
>> str(a)
>> 'Тест'
选择一种能够编码西里尔字母的编码方式,例如 UTF-8:
>>> a = u'Тест'
>>> a.encode('utf-8')
'\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82'