Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • Yes, that's exactly what I was trying to do. I finally achieved that with a less elegant solution than yours using a generator. Commented Oct 20, 2011 at 0:13
  • This leaks the file handle on some Python implementations. You should at least call close. Commented Oct 20, 2011 at 0:29
  • 1
    I've added with statement to close the file properly. Commented Oct 20, 2011 at 2:09
  • 1
    @phihag: is there really python implementation where the automatic close actually leaks file handles ? I thought it merely delayed the releasing of these file handles until garbage collection ? Commented Oct 20, 2011 at 7:05
  • 5
    @RaymondHettinger: if you don't like it; just revert the change. I've considered it to be a too minor change to discuss. Though I strongly disagree with your reasoning. Public code should follow best practices especially if it is aimed for beginners. If best practices are too hard to follow (though I don't think it is the case) for such a common task then the language should change. Commented Sep 5, 2012 at 0:59