简体   繁体   English

Python中的“\\ N {SPECIAL CHARACTER}”来自哪里?

[英]Where does “\N{SPECIAL CHARACTER}” in Python come from?

I came across some urwid tutorial , which included an example with code such as this: 我遇到了一些urwid 教程 ,其中包含一个代码示例如下:

...
main = urwid.Padding(menu(u'Pythons', choices), left=2, right=2)
top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
    align='center', width=('relative', 60),
    valign='middle', height=('relative', 60),
    min_width=20, min_height=9)
urwid.MainLoop(top, palette=[('reversed', 'standout', '')]).run()

That u'\\N{MEDIUM SHADE}' string literal drove me nuts for almost the entire day until I found out it was included — as comments! 那个u'\\N{MEDIUM SHADE}'字符串文字让我疯了几乎整整一天,直到我发现它被包括在内 - 作为评论! — in files under /usr/lib/python3.5/encodings/ ... But nowhere did I find any hint as to using such a notation. - 在/usr/lib/python3.5/encodings/下的文件中......但我没有找到任何关于使用这种表示法的提示。 I browsed Python documentation and could find nothing. 我浏览了Python文档,却什么都找不到。

Out of curiosity I ran in my python interpreter: 出于好奇,我在我的python解释器中运行:

print(u'\N{LOWER ONE QUARTER BLOCK}')

and I got 我得到了

Where does that kind of black magic come from? 那种黑魔法来自哪里? I mean, where is it explained one can use that... notation (?) to print out special characters using their friendly names? 我的意思是,在哪里解释一个人可以使用...符号(?)使用他们友好的名字打印出特殊字符? Does Python hide any other surprises like this one? Python会隐藏像这样的其他惊喜吗?

Towards the end of https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals : 接近https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

\\N{name} - Character named name in the Unicode database \\ N {name} - Unicode数据库中名为name的字符

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

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