简体   繁体   English

如何用unicodedata打印unicode字符的值?

[英]How to print the value of unicode character with unicodedata?

I am trying to print unicode characteres in loop:我正在尝试在循环中打印 unicode 字符:

for i in range(0, 10):
    unicodedata.normalize('NFKD', '\u00a{i}')

But this caused the next error:但这导致了下一个错误:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-4: truncated \uXXXX escape

However the wanted result is:然而想要的结果是:

¡
¢
£
¤
...

Do you have some ideas how to implement this?你有什么想法如何实施吗?

Just use chr(i) ("Return the string representing a character whose Unicode code point is the integer i .") instead of string-formatting things.只需使用chr(i) (“返回表示其 Unicode 代码点为整数i的字符的字符串。”)而不是字符串格式的东西。

>>> for i in range(0, 10):
...     print(chr(0xa0 + i))
...

¡
¢
£
¤
¥
¦
§
¨
©
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM