python 2中未知的unicode输出

python 2中未知的unicode输出,python,netbeans,unicode,python-2.7,netbeans-7.2,Python,Netbeans,Unicode,Python 2.7,Netbeans 7.2,我试图实现从检索一些输入单词的同义词。 当我运行测试方法时 def test(): "tests some functions" a=wn.get_words(True) print 'length of a: ', len(a) print 'a[0]: ', a[0].tostring().decode('utf-8') 输出是未知编码 length of a: 16043 a[0]: ����� 在同一代码中,Unicode已声明为 def _en

我试图实现从检索一些输入单词的同义词。 当我运行测试方法时

def test():
    "tests some functions"
    a=wn.get_words(True)
    print  'length of a: ', len(a)
    print 'a[0]: ', a[0].tostring().decode('utf-8')
输出是未知编码

length of a:  16043
a[0]:  �����
在同一代码中,Unicode已声明为

def _encode(data):
    return data.encode('utf8')
我使用的平台(NetBeans 7.2.1)配置为支持utf-8编码

length of a:  16043
a[0]:  �����

如何解决此问题?

如果已将设置配置为处理UTF-8,则不需要将字符串解码为Unicode对象。接下来将发生的事情是Python使用为
sys.stdout
检测到的当前编码

尝试不解码:

print 'a[0]: ', a[0].tostring()

谢谢你的回答。我使用了这个命令,它对我有效

print 'a[0]: ', a[0].encode('utf-8')

使用
repr(a[0].tostring())
而不是
a[0].tostring().decode('utf-8')
并查看返回的内容。感谢您的建议,但仍然存在相同的问题:(.输出如下:回溯(最近一次调用):文件“AWN.py”,第402行,测试打印“a[0]:”,repr(a[0].tostring())AttributeError:“unicode”对象没有属性“tostring”