O
omission9
I have a text file which contains the occasional non-ascii charcter.
What is the best way to remove all of these in python?
What is the best way to remove all of these in python?
omission9 said:I have a text file which contains the occasional non-ascii charcter.
What is the best way to remove all of these in python?
omission9 said:I have a text file which contains the occasional non-ascii charcter.
What is the best way to remove all of these in python?
omission9 said:I have a text file which contains the occasional non-ascii charcter.
What is the best way to remove all of these in python?
'Hring'>>> orig = "Häring"
>>> "".join([x for x in orig if ord(x) < 128])
Gerhard said:I have a text file which contains the occasional non-ascii charcter.
What is the best way to remove all of these in python?
Here's a simple example that does what you want:
'Hring'orig = "Häring"
"".join([x for x in orig if ord(x) < 128])
'Hring'from string import maketrans, translate
table = maketrans('', '')
translate(orig, table, table[128:])
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.