Python: list object does not have read attribute

I have a single line list containing non-ascii characters. My goal is to get rid of non-ascii characters and convert the list to a string.

Every time I try to cross out non-ascii characters, I get this error: 'list' object has no attribute 'read'

I tried most of these and I still get this error every time. I'm not sure what I'm doing wrong, any help would be appreciated.

+3
source share
2 answers

PY3:

thelist[0].encode('ascii','ignore').decode()

this works for python 2.x:

import string
filter(lambda c:c in string.printable, thelist[0])
+2
source
result = ''.join([s.encode('ascii','ignore') for s in mylist])
0
source

Source: https://habr.com/ru/post/1777574/


All Articles