Re: Filtering out non-readable characters
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Filtering out non-readable characters

From: Bengt Richter <bokr@oz.net>
Date: Sun Jul 24 2005 - 07:04:09 CEST

On Sun, 17 Jul 2005 15:42:08 -0600, Steven Bethard <steven.bethard@gmail.com> wrote:

>Bengt Richter wrote:
>> 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.
>
>I suspect this is bug 905389 [1]:
>
> >>> def gen():
>... yield 1
>... raise TypeError('from gen()')
>...
> >>> ''.join([x for x in gen()])
>Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> File "<interactive input>", line 3, in gen
>TypeError: from gen()
> >>> ''.join(x for x in gen())
>Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
>TypeError: sequence expected, generator found
>
>I run into this every month or so, and have to remind myself that it
>means that my generator is raising a TypeError, not that join doesn't
>accept generator expressions...
>
>STeVe
>
>[1] http://www.python.org/sf/905389

That must have been it, thanks.

Regards,
Bengt Richter
Received on Thu Sep 29 17:08:04 2005