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: Steven Bethard <steven.bethard@gmail.com>
Date: Sun Jul 17 2005 - 23:42:08 CEST

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
Received on Thu Sep 29 16:59:15 2005