Filtering out non-readable characters

George Sakkis gsakkis at rutgers.edu
Sat Jul 16 18:55:42 EDT 2005


"Bengt Richter" <bokr at oz.net> wrote:

>  >>> identity = ''.join([chr(i) for i in xrange(256)])
>  >>> unprintable = ''.join([c for c in identity if c not in string.printable])

Or equivalently:

>>> identity = string.maketrans('','')
>>> unprintable = identity.translate(identity, string.printable)

George





More information about the Python-list mailing list