ValueError: unichr() arg not in range(0x10000) (narrow Python build)

后端 未结 3 1120
星月不相逢
星月不相逢 2020-12-05 19:07

I am trying to convert the html entity to unichar, the html entity is 󮠖 when i try to do the following:

unichr(int(976918))
<         


        
3条回答
  •  抹茶落季
    2020-12-05 19:46

    Here's an alternate workaround that I developed with the struct module.

    def unichar(i):
        try:
            return unichr(i)
        except ValueError:
            return struct.pack('i', i).decode('utf-32')
    
    >>> unichar(int('976918'))
    u'\U000ee816'
    

提交回复
热议问题