【发布时间】:2013-01-04 12:25:19
【问题描述】:
我尝试从NLP UPC research group 实现this code 以检索某些输入单词的同义词。 当我运行测试方法时
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')
我使用的平台(net beans 7.2.1)配置为支持utf-8编码
如何解决这个问题?
【问题讨论】:
-
使用
repr(a[0].tostring())而不是a[0].tostring().decode('utf-8')看看会返回什么。 -
谢谢你的建议,但还是有同样的问题 :( 。输出是这样的: Traceback (most recent call last): File "AWN.py", line 402, in test print 'a[0]: ', repr(a[0].tostring()) AttributeError: 'unicode' 对象没有属性 'tostring'
标签: python netbeans unicode python-2.7 netbeans-7.2