【发布时间】:2014-08-16 18:28:35
【问题描述】:
我已经阅读了Print the "approval" sign/check mark (✓) U+2713 in Python,但没有一个答案对我有用。我在 Windows 上运行 Python 2.7。
print u'\u2713'
产生这个错误:
exceptions.UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to
这个:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
print '✓'
因为我使用的是 Windows,所以不起作用。
print u'\u2713'.encode('utf8')
打印出“”,这不是正确的字符。
print('\N{check mark}')
真是傻。这会按字面意思打印\N{check mark}。
【问题讨论】:
-
赞许您进行了一些研究并准确解释了为什么其他问题的答案对您没有帮助。不过,您不必对此非常激进。 :)
-
请注意,the
print('\N{Check Mark}')answer 似乎假设使用 Python 3,因此错过了 printed string must be aunicoderather than astr的重要一点。
标签: python python-2.7 unicode printing