How can I print all unicode characters?

前端 未结 6 2568
陌清茗
陌清茗 2021-02-19 17:36

I want to print some unicode characters but u\'\\u1000\' up to u\'\\u1099\'. This doesn\'t work:

for i in range(1000,1100):
    s=unico         


        
相关标签:
6条回答
  • 2021-02-19 18:18

    Try the following:

    for i in range(1000, 1100):
        print i, unichr(i)
    
    0 讨论(0)
  • 2021-02-19 18:19

    unichr is the function you are looking for - it takes a number and returns the Unicode character for that point.

    for i in range(1000, 1100):
        print i, unichr(i)
    
    0 讨论(0)
  • 2021-02-19 18:20

    You'll want to use the unichr() builtin function:

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

    Note that in Python 3, just chr() will suffice.

    0 讨论(0)
  • 2021-02-19 18:27

    if you'd like to print the characters corresponding to an arbitrary unicode range, you can use the following (python 3)

    unicode_range = ('4E00', '9FFF')  # (CJK Unified Ideographs)
    characters = []
    for unicode_character in range(int(unicode_range[0], 16), int(unicode_range[1], 16)):
        characters.append(chr(unicode_character))
    
    0 讨论(0)
  • 2021-02-19 18:32

    Use unichr:

    s = unichr(i)
    

    From the documentation:

    unichr(i)

    Return the Unicode string of one character whose Unicode code is the integer i. For example, unichr(97) returns the string u'a'.

    0 讨论(0)
  • 2021-02-19 18:32

    One might appreciate this php-cli version:

    It is using html entities and UTF8 decoding.

    Recent version of XTERM and others terminals supports unicode chars pretty nicely :)

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

    0 讨论(0)
提交回复
热议问题