【问题标题】:Printing unicode character from number [duplicate]从数字打印unicode字符[重复]
【发布时间】:2017-06-20 10:38:39
【问题描述】:

在 Python 中,我试图打印出与给定代码对应的字符,如下所示:

a = 159
print unichr(a)

它打印出一个奇怪的符号。谁能解释一下为什么?

【问题讨论】:

  • 您希望得到哪个 unicode 字符?

标签: python unicode


【解决方案1】:
#To get numerical value of string. This gives me 49.
ord("1")

#To get string from numerical value. This gives me "1".
chr(49)

您尝试转换为数字的数值可能代表特殊字符,在这种情况下,python 很可能将其转换为十六进制等效值。查看整数的十六进制值:

hex(ord("1"))

如果不是这样,它可能使用了另一个代表,因为它(假设)是一个特殊字符。

【讨论】:

  • 这并不能解释为什么 OP 会出现这个问题。
【解决方案2】:

unicode 159 处的字符是应用程序命令。它是一个控制字符,并且被视为不是图形字符

More information

【讨论】:

    猜你喜欢
    • 2018-06-22
    • 2014-08-23
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多