Generator expression parenthesis mixed with function call ones

Laurent Pointal laurent.pointal at limsi.fr
Wed Mar 7 10:53:43 EST 2007


[Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32]

Given the following:

>>> sum(i for i in range(10))
45
>>> def f(*args) : print args
...
>>> f(i for i in range(10))
(<generator object at 0x00A79788>,)
>>> def f(a,*args) : print a,ar
...
>>> f(4,i for i in range(10))
  File "<stdin>", line 1
SyntaxError: invalid syntax


Why does Python allow generator expression parenthesis to be mixed with
function call parenthesis when there is only one parameter ?

IMHO this should be forbidden, usage must not be different when there is
only one parameter and when there are more parameters.
User should all times explicitly use () for a generator expression and
[] for a list comprehension expression.





More information about the Python-list mailing list