0
鉴于这个例子中,我得到下面的错误:Python的string.translate()不能完全工作?
print u'\2033'.translate({2033:u'd'})
C:\Python26\lib\encodings\cp437.pyc in encode(self, input, errors)
10
11 def encode(self,input,errors='strict'):
---> 12 return codecs.charmap_encode(input,errors,encoding_map)
13
14 def decode(self,input,errors='strict'):
UnicodeEncodeError: 'charmap' codec can't encode character u'\x83' in position 0
好的,这是有道理的。我不明白为什么下面的解决方案不适用于2033年。 @stuboverflow.com/posts/2854253/revisions – Rhubarb 2010-06-11 00:39:07
@Rhubarb:如果你指的是解决方案使用'unidecode'和'translate',它适用于我:它用'u'代替'u“\''''' – interjay 2010-06-11 00:58:14
很奇怪,你能发布你使用过的确切代码吗?我从该解决方案得到的副本/版本返回一个空字符串。 – Rhubarb 2010-06-11 01:07:01