[Python-ideas] With clauses for generator expressions

Serhiy Storchaka storchaka at gmail.com
Thu Nov 15 08:50:52 CET 2012


On 15.11.12 05:44, Andrew Barnert wrote:
> That's why we still have tons of code like this lying around:
>
>      upperlines = (lines.upper() for line in open('foo', 'r'))
>
> Everyone knows that this only works with CPython, and isn't even quite right
> there, and yet people write it anyway, because there's no good alternative.

Not every piece of code should be written as one-liner.

Use a generator function.





More information about the Python-ideas mailing list