gpt4 book ai didi

python - 在 python 中使用马拉雅拉姆语 unicode

转载 作者:行者123 更新时间:2023-11-30 23:26:27 27 4
gpt4 key购买 nike

代码:

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>

请提供解决方案。

最佳答案

以下代码在 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)

കക

关于python - 在 python 中使用马拉雅拉姆语 unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22507342/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com