Python: 'list' object has no attribute 'read'
I have a list with a single string th开发者_Python百科at contains non-ascii characters. My goal is to get rid of the non-ascii characters and convert the list to a string.
Every time I try to strip out the non-ascii characters, I get this error: 'list' object has no attribute 'read'
I've tried most of these and I still get this error every time. I'm not sure what I am doing wrong, any help would be appreciated.
Py3:
thelist[0].encode('ascii','ignore').decode()
this works for python 2.x:
import string
filter(lambda c:c in string.printable, thelist[0])
result = ''.join([s.encode('ascii','ignore') for s in mylist])
For this you want to activate the virtaulenv
From this way it worked!
精彩评论