generator construction
Terry Reedy
tjreedy at udel.edu
Wed Dec 4 11:07:40 EST 2002
"Eric van Riet Paap" <eric2 at vanrietpaap.com> wrote in message
news:3dee2207$0$94299$e4fe514c at dreader4.news.xs4all.nl...
> Hi,
>
> I was building a recursive generator which had this code in it:
> for node in Nodes(child):
> yield node
>
> As an experiment I tried this list comprehension version:
> [yield node for node in Nodes(child)]
>
> I understand that the list goes nowhere, but I thought it was a
valid
> construction.
> Why do I get a "SyntaxError: invalid syntax" error?
yield x is a statement, not an expression
[print x for x in seq] would be similar error
Terry J. Reedy
More information about the Python-list
mailing list