[Python-Dev] Re: PEP 289 - Generator Expressions - Let's Move Forward

Russell E. Owen rowen at cesmail.net
Fri Apr 30 17:00:08 EDT 2004

In article < at pop.bluewin.ch>,
 Samuele Pedroni <pedronis at bluewin.ch> wrote:

> this assumes that people will choose either generator expressions or list 
> comprehesions on a case-by-case basis. I'm not sure it's a reasonable 
> assumption for the whole range of users - starting with newbies. Probably 
> documentation and what is predicated on c.l.p will influence this.

I completely agree. Generator expressions and list comprehensions are 
similar enough that it seems a wart to have to carefully differentiate 
between two in normal use. 

Personally, I'd only like to see generator expressions added to Python 
if they can allow list comprehensions to be deprecated -- to avoid 
language clutter.

One question, though: is "if" part of generator expressions or not? I 
read the current version of the PEP and I'm confused. It offers the 

max(len(line)  for line in file  if line.strip())

But that is the only instance in the PEP that I noticed. The section 
"The Details" says almost nothing about "if". The only thing I found 
that might be relevant appeared at the end of: "2. The syntax 
requires...": "...where listmaker1 is almost the same as listmaker, but 
only allows a single test after 'for' ... 'in'." I suppose that might be 
saying that a single "if" condition is allowed. If so, great!

-- Russell

More information about the Python-Dev mailing list