Skip to content

Instantly share code, notes, and snippets.

@ripiuk
Last active April 1, 2018 14:29
Show Gist options
  • Save ripiuk/e94dfa70cb476f0cca7b4c3157dee719 to your computer and use it in GitHub Desktop.
Save ripiuk/e94dfa70cb476f0cca7b4c3157dee719 to your computer and use it in GitHub Desktop.
Remove non-ASCII characters
import string
def _remove_non_ascii(text: str):
return ''.join(ch for ch in filter(lambda x: x in string.printable, text)) if isinstance(text, str) else text
_remove_non_ascii('¬äº‹é”æ—店 - 西門店 (台北市) Wonstar - Ximen') # output: ' - () Wonstar - Ximen'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment