簡體   English   中英

如何打印所有 unicode 字符?

[英]How can I print all unicode characters?

["

for i in range(1000,1100):
    s=unicode('u'+str(i))
    print i,s

您需要使用unichr()內置函數:

for i in range(1000,1100):
    print i, unichr(i)

請注意,在 Python 3 中,只需chr()就足夠了。

使用unichr

s = unichr(i)

從文檔中:

unichr(i)

返回其 Unicode 代碼為整數 i 的一個字符的 Unicode 字符串。 例如,unichr(97) 返回字符串 u'a'。

嘗試以下操作:

for i in range(1000, 1100):
    print i, unichr(i)

unichr是您正在尋找的函數 - 它接受一個數字並返回該點的 Unicode 字符。

for i in range(1000, 1100):
    print i, unichr(i)

(Python 3)以下將為您提供與任意 unicode 范圍相對應的字符

start_code, stop_code = '4E00', '9FFF'  # (CJK Unified Ideographs)
start_idx, stop_idx = [int(code, 16) for code in (start_code, stop_code)]  # from hexadecimal to unicode code point
characters = []
for unicode_idx in range(start_idx, stop_idx+1):
    characters.append(chr(unicode_idx))

使用chr而不是unichr以避免出現錯誤消息。

for i in range(1000, 1100):
    print i, chr(i)

人們可能會喜歡這個php-cli版本:

它使用 html 實體和 UTF8 解碼。

XTERM 和其他終端的最新版本很好地支持 unicode 字符 :)

php -r 'for ($x = 0; $x < 255000; $x++) {echo html_entity_decode("&#".$x.";",ENT_NOQUOTES,"UTF-8");}'

在此處輸入圖像描述

暫無
暫無

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

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