Generator expression parenthesis mixed with function call ones

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Mar 7 16:17:26 EST 2007


En Wed, 07 Mar 2007 15:21:57 -0300, Laurent Pointal  
<laurent.pointal at wanadoo.fr> escribió:

> Gabriel Genellina wrote:
>
>> En Wed, 07 Mar 2007 12:53:43 -0300, Laurent Pointal
>> <laurent.pointal at limsi.fr> escribió:
>>
>>> Why does Python allow generator expression parenthesis to be mixed with
>>> function call parenthesis when there is only one parameter ?
>Beginners generally know about list-comprehensions and associate the
> syntax "x for x in asequence" to a list expression. I'm not sure that

But list comprehensions have [] around... When you don't see the [], you  
should think "this is something different"...

> reading a "f(i for i in range(20))" they understand that they are dealing
> with a different object kind.

Exactly.

> If function f start by a if len(myparameter)...
>   TypeError: len() of unsized object
>
> If function f goes among its parameter with "for x in myparameter" more  
> than
> once, other loops goes throught an empty loop.

Then he thinks "Something is wrong!", and reads some Python books, or asks  
here, and somebody will point him to the Python Tutorial, section 9.11:  
http://docs.python.org/tut/node11.html#SECTION00111100000000000000000

>>> IMHO this should be forbidden, usage must not be different when there  
>>> is only one parameter and when there are more parameters.

If you want to review the original discussion on how to spell a generator  
expression (called "accumulator display" by that time) see  
http://mail.python.org/pipermail/python-dev/2003-October/038868.html

-- 
Gabriel Genellina




More information about the Python-list mailing list