Filtering out non-readable characters

Bengt Richter bokr at oz.net
Sat Jul 16 18:18:53 EDT 2005


On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen <peter at engcorp.com> wrote:

>Bengt Richter wrote:
>>  >>> identity = ''.join([chr(i) for i in xrange(256)])
>>  >>> unprintable = ''.join([c for c in identity if c not in string.printable])
>
>And note that with Python 2.4, in each case the above square brackets 
>are unnecessary (though harmless), because of the arrival of "generator 
>expressions" in the language.  (Bengt knows this already, of course, but 
>his brain is probably resisting the reprogramming.  :-) )
>
Thanks for the nudge. Actually, I know about generator expressions, but
at some point I must have misinterpreted some bug in my code to mean
that join in particular didn't like generator expression arguments,
and wanted lists. Actually it seems to like anything at all that can
be iterated produce a sequence of strings. So I'm glad to find that
join is fine after all, and to get that misap[com?:-)]prehension
out of my mind ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list