Python:乳胶符号到unicode?
我喜欢几个暗示如何解决 unicode 到乳胶符号转换的答案。例如将 u'á'
转换为 \'{a}
。
好吧,我需要它相反!所以我做了一些研究并喜欢这本字典。由于映射似乎是双射的,因此我想到将字典反过来。但我不知道如何“使用”这本字典中的键:
u"\u0020": "\\space ",
u"\u0023": "\\#",
u"\u0024": "\\textdollar ",
u"\u0025": "\\%",
如何将它们在 python 中转换为“人类可读字符”? 是否有更好、更完整的方法来实现我的目标?
I have fond several answers hinting how to solve unicode to latex symbols conversion. For example turning u'á'
into \'{a}
.
Well I need it the other way around! So I made some research and fond this dictionary. Since the mapping seems to be bijective, I thought of turning the dictionary the other way around. But I can't figure out how to "use" the keys in this dictionary:
u"\u0020": "\\space ",
u"\u0023": "\\#",
u"\u0024": "\\textdollar ",
u"\u0025": "\\%",
How can I turn them inside python to "human readable characters"?
Is there mayhaps a better and more complete was to achieve my goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
符号
u'\u0020'
只是一个指定空格字符的转义序列,只不过它是通过字符代码指定它来实现的。字典的作者可能是这样做的,这样如果缺少某些内容就会很明显,但您不需要执行任何特殊转换即可使用字典,因为u'\u0020' == ' '
。The notation
u'\u0020'
is just an escape sequence that specifies the space character, only it does so by specifying it by character code. The author of the dictionary probably did it this way so that it would be obvious if something was missing, but you don't need to perform any special conversion to use the dictionary, sinceu'\u0020' == ' '
.... 什么?
(也就是说,它们已经是角色;您无需对它们执行任何操作。)
... What?
(That is, they're already characters; you need do nothing to them.)