Reputation: 5082
I have a list with a single string that 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.
Upvotes: 4
Views: 40893
Reputation: 89
For this you want to activate the virtaulenv
From this way it worked!
Upvotes: 0
Reputation: 10663
Py3:
thelist[0].encode('ascii','ignore').decode()
this works for python 2.x:
import string
filter(lambda c:c in string.printable, thelist[0])
Upvotes: 2
Reputation: 56654
result = ''.join([s.encode('ascii','ignore') for s in mylist])
Upvotes: 0