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)