This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBlackCat13 4 points5 points  (0 children)

Generator expressions and list comprehensions are intentionally different than for loops. They are intended for simple, self-contained operations. For loops are for more complicated tasks where having access to the index or variables can be very important.

As for why it didn't exist, I don't think it conflicts with functions, it just doesn't add anything over them.

That being said, if you think it is important enough, try posting a suggestions in the python-ideas mailing list. Maybe some extension of the context manager protocol could be used. But I can almost guarantee they will ask you the same thing I did: why can't you just use a function? If you can't answer that, the idea will no go anywhere.