![](/img/trans.png)
[英]How to decode the unicode string starting with “%u” (percent symbol + u) in Python 3
[英]In Python 3 how to print unicode codepoint as u'\U…'
无论出于何种原因,我认为创建一个我感兴趣的表情符号表会很好。第一列是代码点,第二列是表情符号,第三列是名称。 与此网页类似的内容,但适合我的使用。
假设我弄清楚如何迭代代码点(还有其他问题或者我构建了一个感兴趣的列表)然后我将循环遍历代码点,例如
u_str = u'\U0001F001'
u_str = u'\U0001F002'
(当然以编程方式生成)
并打印(循环):
print(u'\U0001F001', u_str, ' ', unicodedata.name(u_str))
print(u'\U0001F002', u_str, ' ', unicodedata.name(u_str))
如果有能力使用 unicodedata 和一些属性,如 unicodedata.hex_representation 那么我会使用它,但如果 unicodedata 中有该属性,我不明白看到它的规范。
所以在寻找答案时,我发现了这个问题:
怎么做-一个打印-一个-unicode-character-code-in-python
我尝试:
>>> print(u_str.encode('raw_unicode_escape'))
b'\\U0001f600'
我正在寻找的是我放入的内容:
u_str = u'\U0001F600'
这是可能的还是有其他方法可以实现表格的构建?
使用 Python 3.6+:
>>> for i in range(0x1f001,0x1f005):
>>> print(f'U+{i:04X} \\U{i:08X} {chr(i)}')
U+1F001 \U0001F001 🀁
U+1F002 \U0001F002 🀂
U+1F003 \U0001F003 🀃
U+1F004 \U0001F004 🀄
原始表示永远消失了。 大小写和格式由 Python 本身指定。
您需要将字节解码回文本。 尝试ascii
编解码器,因为这就是raw_unicode_escape
会生成的全部raw_unicode_escape
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.