【发布时间】:2018-11-27 07:21:34
【问题描述】:
我有一个列表形式的 unicode 字符串列表。
my_list = [u'[James, Williams, Kevin, Parker, Alex, Emma, Katie\xa0, Annie]']
我想要一个可以迭代的列表,例如;
name_list = [James, Williams, Kevin, Parker, Alex, Emma, Katie, Annie]
我已经尝试了几种可能的解决方案here,但在我的情况下它们都不起作用。
# Tried
name_list = name_list.encode('ascii', 'ignore').decode('utf-8')
#Gives unicode return type
# Tried
ast.literal_eval(name_list)
#Gives me invalid token error
【问题讨论】:
-
如果你只是学习Python,你应该忽略Python 2。目前支持和推荐的语言版本是Python 3。
-
name_list = [James, Williams...在 Python 中是非法的。你想要的是name_list = ['James', 'Williams'...
标签: python list unicode unicode-escapes