繁体   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