【问题标题】:Python - How to convert Unicode code point to the characterPython - 如何将 Unicode 代码点转换为字符
【发布时间】:2018-07-03 01:24:57
【问题描述】:

我正在尝试将英文字符转换为 Star Wars Aurebesh 字符。 我在这里找到了 Aurebesh 字符的 unicode 代码分配:http://www.kreativekorp.com/ucsur/charts/aurebesh.htm

那么使用“U+E890”这样的代码点,我可以在python中打印出Aurebesh字符吗?

【问题讨论】:

  • 尝试简单地使用:print u'\ue890'

标签: python unicode


【解决方案1】:

print('\ue890') 将完成这项工作。

【讨论】:

  • 无法打印出星球大战的角色,只能打印出一个空方格……
  • 你必须以支持 Aurebesh 的字体显示:fontspace.com/category/aurebesh
  • 你知道如何在 IPython 中添加这种字体吗?我下载了字体,但只能在我的 PowerPoint 中使用...
【解决方案2】:

在 python3 中,您可以使用转义字符来做到这一点: print('\ue890')

编辑: 将此添加到答案中,因为它涉及 cmets 中的一个小讨论。

在 python2.7 中,您需要在字符串前面添加额外的 u 以将其转换为 unicode 字符串(由 Matt Clark 提供): print u'\ue890'

【讨论】:

  • 你需要先将整个字符串定义为unicode:print(u'\ue890')
  • 您不再需要在 python 3 中这样做。
  • python 3 为 print(u'\ue890')print('\ue890') @MattClark 提供相同的结果
  • 嗯,是吗?好的。 2.7 需要前置u
  • python3 让你的 Python 生活更轻松! @MattClark
猜你喜欢
  • 1970-01-01
  • 2013-04-29
  • 1970-01-01
  • 1970-01-01
  • 2018-09-20
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多