簡體   English   中英

如何在python中將大代碼點轉換為unicode字符?

[英]How to convert large codepoint to unicode character in python?

我收到以下錯誤。 有人知道如何獲取與大代碼點相對應的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被配置為UCS2。 從文檔中

返回一個字符的Unicode字符串,其Unicode代碼為整數i。 例如,unichr(97)返回字符串u'a'。 這與Unicode字符串的ord()相反。 參數的有效范圍取決於Python的配置方式-可以是UCS2 [0..0xFFFF]或UCS4 [0..0x10FFFF]。 否則將引發ValueError。 有關ASCII和8位字符串,請參見chr()。

正如上面發表在評論中的, 這個問題有各種答案,我可以為您提供解決方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM