Python - Convert unicde list to string
Posted In:
Python
.
By CreativeSolutions
import ast
//data is the uncode list like u"[u'1', u'2', u'3', u'4']"
s = [ item.encode('ascii') for item in ast.literal_eval(data) ]
val = ', '.join(s)
If we try to convert to string using the join function it will not work and it will combine all the characters in the string. so we need to use the ast eval function with ascii encoding.
//data is the uncode list like u"[u'1', u'2', u'3', u'4']"
s = [ item.encode('ascii') for item in ast.literal_eval(data) ]
val = ', '.join(s)
If we try to convert to string using the join function it will not work and it will combine all the characters in the string. so we need to use the ast eval function with ascii encoding.