Given a unicode object:
u'[obj1,obj2,ob3]'
How do you convert it to a normal list of objects?
import ast
s = u'[obj1,obj2,ob3]'
n = ast.literal_eval(s)
n
[obj1, obj2, ob3]
Did you mean this? Converting a unicode string to a list of strings. BTW, you need to know the encoding when dealing with unicode. Here I have used utf-8
>>> s = u'[obj1,obj2,ob3]'
>>> n = [e.encode('utf-8') for e in s.strip('[]').split(',')]
>>> n
['obj1', 'obj2', 'ob3']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With