Facundo Batista a écrit : > Laurent Pointal wrote: > > >>>>> 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 ? > > For simplicity and elegant coding, so you can do something like you did > at first: > > sum(i for i in range(10))
How a Python beginner know that he is using a generator and not a list-comprehension ? >> IMHO this should be forbidden, usage must not be different when there is >> only one parameter and when there are more parameters. > > The problem in your last test is that if you use more than one argument, > you *must* use the parenthesis. In Py2.5 there's a better message error: > >>>> f(4,i for i in range(10)) > File "<stdin>", line 1 > SyntaxError: Generator expression must be parenthesized if not sole argument > > > The correct way to do that is: > >>>> f(4,(i for i in range(10))) > 4 (<generator object at 0xb7dab56c>,) Thanks, I know. My example is just to show a point I consider to be non-coherent (different processing if there is one argument or more than one). A+ Laurent. -- http://mail.python.org/mailman/listinfo/python-list