在Python中使用马拉雅拉姆Unicode

1 投票
1 回答
2179 浏览
提问于 2025-04-17 22:58

这段代码:

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

在Python 3.0的命令行中运行时,输出结果是കക,这是正确的。但是当我在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 个回答

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)

കക

撰写回答