Python 简单编码“UTF-8”错误

Python 简单编码“UTF-8”错误,python,windows,python-2.7,unicode,hebrew,Python,Windows,Python 2.7,Unicode,Hebrew,以下字符串“a”是希伯来语: # -*- coding: utf-8 -*- a = u'אבא' print a 产生以下错误: Traceback (most recent call last): File "database.py", line 13, in <module> print a File "C:\Python27\lib\encodings\cp437.py", line 12, in encode return codecs.charm

以下字符串“a”是希伯来语:

# -*- coding: utf-8 -*-
a = u'אבא'
print a
产生以下错误:

Traceback (most recent call last):
  File "database.py", line 13, in <module>
    print a
  File "C:\Python27\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to <undefined>

我得到了很多输出,但没有一个是希伯来语。

对我来说效果很好。你还在对编码字符串做什么吗?没有。。。你看到的是我所做的你运行Python的标准Windows cmd提示符?是的,但我的cmd框配置了希伯来文字体。。。这是从cmd.exe运行Python的一个已知问题。有一些变通方法,但使用另一个终端或python的空闲可能是更容易/更好的选择。
a = 'אבא'
print a.decode('cp862').encode('cp862')
print a.decode('cp862').encode('utf-8')
print a.decode('utf-8').encode('utf-8')
print a.decode('utf-8').encode('cp424')
print a.decode('utf-8').encode('cp856')
print a.decode('utf-8').encode('iso8859_8')
print a.decode('utf-8').encode('cp1255')
print a.decode('utf-8').encode('utf-8')