
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

On Tue, Jan 13, 2009 at 11:12 PM, Carl Johnson <carl@carlsensei.com> wrote:
Fairly doomed, IMHO. To be consistent at all, Python would also have to allow the related Perlisms of: x **= 2 while x < y x += y for y in z x.sort() if should_sort which seem pretty gross to me as the control structure gets somewhat hidden. And as you pointed out, it's just plain unnecessary since such code can already be written as a one-liner, with the advantage of less reformatting if it later becomes a multiliner. Also, having a consistent order of block-statement before block-body enhances the uniformity of the language. About the only good examples of block bodies coming before block statements which I can think of offhand are do-while and Haskell's `where` clause, which both seem to me to be sufficiently special cases as to not have bearing here. That's my 2¢ anyway. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com

On Sun, Jan 18, 2009 at 2:41 PM, Leif Walsh <leif.walsh@gmail.com> wrote:
I always preferred: data = open("file.txt").read() Which works all the way back as far as I can remember. And as for: strippedLines = [sline for line in lines with line.strip() as sline if sline] Try: strippedLines = [sline for sline in (line.strip() for line in lines) if sline] The request gets a big fat -1 from me. - Josiah

On Tue, Jan 20, 2009 at 8:00 AM, Sturla Molden <sturla@molden.no> wrote:
We cannot and should not define aspects of the language which do (especially on purpose) specifically deny other implementations from respecting that change.
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

On Tue, Jan 13, 2009 at 11:12 PM, Carl Johnson <carl@carlsensei.com> wrote:
Fairly doomed, IMHO. To be consistent at all, Python would also have to allow the related Perlisms of: x **= 2 while x < y x += y for y in z x.sort() if should_sort which seem pretty gross to me as the control structure gets somewhat hidden. And as you pointed out, it's just plain unnecessary since such code can already be written as a one-liner, with the advantage of less reformatting if it later becomes a multiliner. Also, having a consistent order of block-statement before block-body enhances the uniformity of the language. About the only good examples of block bodies coming before block statements which I can think of offhand are do-while and Haskell's `where` clause, which both seem to me to be sufficiently special cases as to not have bearing here. That's my 2¢ anyway. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com

On Sun, Jan 18, 2009 at 2:41 PM, Leif Walsh <leif.walsh@gmail.com> wrote:
I always preferred: data = open("file.txt").read() Which works all the way back as far as I can remember. And as for: strippedLines = [sline for line in lines with line.strip() as sline if sline] Try: strippedLines = [sline for sline in (line.strip() for line in lines) if sline] The request gets a big fat -1 from me. - Josiah

On Tue, Jan 20, 2009 at 8:00 AM, Sturla Molden <sturla@molden.no> wrote:
We cannot and should not define aspects of the language which do (especially on purpose) specifically deny other implementations from respecting that change.
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
participants (9)
-
Calvin Spealman
-
Carl Johnson
-
Chris Rebert
-
Gregory P. Smith
-
Josiah Carlson
-
Leif Walsh
-
Mathias Panzenböck
-
Sturla Molden
-
Terry Reedy