python - Getting rid of unicode characters in a list -
i've tried str() , x.encode('utf8'). there quick , easy way remove unicode chars? list looks this:
mcd = [u'chicken saut\xc3\xa9ed potatoes', 'roasted lamb mash potatoes', 'rabbit casserole tarragon, mushrooms , dijon mustard sauce. served mash potatoes']
the reason trying rid of u's becasue i'd copy data onto csv file. gives me error 1 below when try so...
unicodeencodeerror: 'ascii' codec can't encode characters in position 8-10: ordinal not in range(128)
i thought easier remove unicode altogether.
thanks in advance!
this works me:
mcd = [u'chicken saut\xc3\xa9ed potatoes', 'roasted lamb mash potatoes', 'rabbit casserole tarragon, mushrooms , dijon mustard sauce. served mash potatoes'] new = [str(m) m in mcd] m,n in zip(mcd,new): # compare before , after print type(m), type(n)
out:
<type 'unicode'> <type 'str'> <type 'str'> <type 'str'> <type 'str'> <type 'str'>
if above doesn't work (see convo in comments):
new = [m.encode('utf-8') m in mcd]
Comments
Post a Comment