Filtering out non-readable characters
Steven Bethard
steven.bethard at gmail.com
Sun Jul 17 17:42:08 EDT 2005
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
More information about the Python-list
mailing list