Filtering out non-readable characters

Bengt Richter bokr at oz.net
Sun Jul 24 07:04:09 CEST 2005


On Sun, 17 Jul 2005 15:42:08 -0600, Steven Bethard <steven.bethard at 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



More information about the Python-list mailing list