我在使用Unicode的Python中遇到问题。我需要绘制一个带有Unicode注释的图形。根据tutorial我应该在Unicode中创建我的字符串。我这样做:Python:创建一个Unicode字符串
annotation = u"%s has %s rev"%(art.title, len(art.revisions))
它是在其中有Unicode字符的art.title
。有时候,代码有效,有时会给我下面的错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)
我该如何解决它?
编辑: 我有错误后,正是“注释”行:
File "script.py", line 195, in test_trie
annotation = u"%s has %s rev"%(art.title, len(art.revisions))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 19: ordinal not in range(128)
'art.title'从哪里来? – 2012-04-20 00:36:21
你确定错误信息是给你的代码行吗?我怀疑当你输出'annotation'时实际发生错误。在这种情况下,你能否显示该代码行? – jogojapan 2012-04-20 03:26:23
@jogojapan是的,请参阅编辑问题。 – ashim 2012-04-20 03:40:50