Created
August 18, 2016 19:36
-
-
Save gaotongfei/53185817ad5d92b11ab849c19313bb47 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
s = "Miljkovi´c, K¨all" | |
printable = set(string.printable) | |
print(filter(lambda x: x in printable, s)) | |
<!--more--> | |
结果: | |
` | |
Miljkovic, Kall | |
` | |
或者用正则表达式: | |
{% highlight python %} | |
import re | |
s = "Miljkovi´c, K¨all" | |
print(re.sub(r'[^\x00-\x7f]', r'', s)) | |
{% endhighlight %} | |
参考自[stackoverflow](http://stackoverflow.com/questions/8689795/how-can-i-remove-non-ascii-characters-but-leave-periods-and-spaces-using-python/8689826#8689826) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment