UnicodeEncodeError:'ascii'编解码器无法对位置32中的字符u'\ u2019'进行编码:序数不在范围内(128)

时间:2017-04-12 18:12:13

标签: python python-2.7 unicode encoding

我有一个字符串列表如下:

[u'Any subscription charges to avail this facility',
 u'credited into the beneficiary\u2019s account',
 u'funds have been credited in the beneficiary\u2019s account',
 u'Can I reuse VPA']

字符串(\ u2019)中有一些unicode char表示(')标点符号。请让我知道如何删除此作为创建错误。我使用下面的代码删除但不起作用:

for x in mylist:
  x.encode('ascii','ignore')
  new_list.append(x)

但它返回与unicode字符相同的列表。请帮忙

1 个答案:

答案 0 :(得分:0)

您没有将编码值附加到new_list。

for x in mylist:
   new_list.append(x.encode('ascii','ignore'))


['Any subscription charges to avail this facility', 
'credited into the beneficiarys account', 
'funds have been credited in the beneficiarys account', 
'Can I reuse VPA']