[Python-ideas] With-expression

Mathias Panzenböck grosser.meister.morti at gmx.net
Wed Jan 14 12:33:02 CET 2009


strippedLines = [sline for line in lines with line.strip() as sline if sline]

or something like that. :P
(-1)

	-panzi

Carl Johnson schrieb:
> From the department of doomed ideas:
>
>      data = f.read() with open("file.txt") as f
>
> Has the idea of a with-expression already been preemptively shot down?
>
> I guess the objection is that the above could easily be rewritten as
>
>     data = read_and_close("file.txt")
>
> if one defines the appropriate function. The counter-objection is that
> why do I need to write a micro-function when the with-statement already
> does what I want, except it takes up two lines when it would still be
> clear as one line. But then the counter-counter-objection is that you
> can write
>
>     with open("file.txt") as f: data = f.read()
>
> today. To which the counter-counter-counter-objection is, yeah, but that
> looks cluttered and ugly in a way that the first example doesn't...
> Except the first example is sort of cluttered.
>
> I dunno, what do other people think about this? Doomed or super-doomed?
>
> -- Carl



More information about the Python-ideas mailing list