Gregory P. Smith
greg at krypto.org
Tue Jan 20 02:47:56 CET 2009
On Mon, Jan 19, 2009 at 5:46 PM, Josiah Carlson <josiah.carlson at gmail.com>wrote:
> On Sun, Jan 18, 2009 at 2:41 PM, Leif Walsh <leif.walsh at gmail.com> wrote:
> > On Wed, Jan 14, 2009 at 2:12 AM, Carl Johnson <carl at carlsensei.com>
> >> From the department of doomed ideas:
> >> data = f.read() with open("file.txt") as f
> > "Who do you think we are, Ruby?"
> > Just kidding, but -1.
> I always preferred:
> data = open("file.txt").read()
> Which works all the way back as far as I can remember.
In C Python yes that "works" but it makes absolutely no guarantees about
when that file is actually closed. Don't write code that depends on a
particular GC behavior. Use with. :)
> And as for:
> strippedLines = [sline for line in lines with line.strip() as sline if
> strippedLines = [sline for sline in (line.strip() for line in lines) if
> The request gets a big fat -1 from me.
> - Josiah
> Python-ideas mailing list
> Python-ideas at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas