【问题标题】:How to convert large codepoint to unicode character in python?如何在python中将大代码点转换为unicode字符?
【发布时间】:2019-08-12 14:15:27
【问题描述】:

我收到以下错误。有人知道如何获取与大代码点相对应的 Unicode 字符吗?谢谢。

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 29 2018, 20:59:26) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> unichr(119964)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unichr() arg not in range(0x10000) (narrow Python build)

【问题讨论】:

标签: python unicode python-unicode


【解决方案1】:

看起来您的 python 配置为 UCS2。来自文档

返回一个字符的 Unicode 字符串,其 Unicode 代码是 整数 i。例如,unichr(97) 返回字符串 u'a'。这是 Unicode 字符串的 ord() 的倒数。的有效范围 参数取决于 Python 的配置方式——它可能是 UCS2 [0..0xFFFF] 或 UCS4 [0..0x10FFFF]。否则会引发 ValueError 。为了 ASCII 和 8 位字符串见 chr()。

正如上面在评论this 中发布的那样,问题有各种答案,我为您提供了一种解决方法。

【讨论】:

  • 我使用python网站上的python 2安装包 for Mac。 USC4安装包如何获取?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
  • 1970-01-01
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
  • 2021-10-27
  • 2020-01-21
相关资源
最近更新 更多