在python中使用Malayalam unicode

时间:2014-03-19 13:26:21

标签: python unicode character-encoding python-unicode

代码:

import unicodedata
s=u'കക'
b=s.encode('utf-8').decode('utf-8')
print(b)

在Python 3.0 shell中以കക生成正确的输出。但是当我在Spyder(Python 2.7)(设置为默认编码方案utf-8)中尝试相同时,它显示错误为:

return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to <undefined>

请提供解决方案。

1 个答案:

答案 0 :(得分:3)

以下代码在Ubuntu 14.04和Python 2.7.6中生成正确的输出

#!/usr/bin/python
# -*- coding: utf_8 -*-
import unicodedata
s=u'കക'
b=s.encode('utf-8').decode('utf-8')
print(b)

കക