【发布时间】:2017-09-08 15:51:19
【问题描述】:
我有一个下面给出的字符串列表:
[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 字符相同的列表。请帮忙
【问题讨论】:
-
你能用简单的
'替换\u2019吗?或者 b) 使用utf-8而不是ascii编码? -
@MadPhysicist,你能告诉我怎么做吗?在代码中
-
x.encode()返回编码后的结果,不会修改 x: 你想要的:new_list.append(x.encode('ascii','ignore')) -
啊,你打败了我
-
@TemporalWolf,谢谢!!你的方法有效
标签: python python-2.7 unicode encoding