How to remove this \xa0 from a string in python?

If you know for sure that is the only character you don’t want, you can .replace it:

>>> word.replace(u'\xa0', ' ')
u'Buffalo, IL 60625'

If you need to handle all non-ascii characters, encoding and replacing bad characters might be a good start…:

>>> word.encode('ascii', 'replace')
'Buffalo,?IL?60625'

Leave a Comment

tech