简体   繁体   English

如何打印包含unicode字符的变量?

[英]How to print a variable that contains a unicode character?

print u'\u0D05'
a = '\u0D05'
print a

print a gives \അ as output but I want to print the unicode character it represents, which is . print a给出\അ作为输出,但我想打印它代表的unicode字符,即 How can I achieve this? 我怎样才能做到这一点?

The \\u\u003c/code> escape is not meaningful inside a non-unicode string. \\u\u003c/code>转义在非unicode字符串中没有意义。 You need to do a = u'\അ' . 你需要做a = u'\അ'

If you're saying you're getting the string from somewhere else and need to interpret unicode escapes in it, then do print a.decode('unicode-escape') 如果你说你从其他地方获取字符串并且需要解释其中的unicode转义,那么请print a.decode('unicode-escape')

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

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