On Mon, Oct 24, 2011 at 2:08 AM, Chris Rebert <c...@rebertia.com> wrote:
> On Sun, Oct 23, 2011 at 10:18 PM, Jason Swails <jason.swa...@gmail.com> > wrote: > > > unless, of course, I add an explicit reference to track the open file > object > > and manually close or flush it > > (but I'd like to avoid it if possible). > > Why? Especially when the performance cost is likely to be nontrivial... > Because if the CSV API exposed the file object, I wouldn't have to create that extra reference, and the class that is handling this stuff already has enough attributes without having to add a separate one for each CSV writer it instantiates. It's not a serious objection to creating it, just one I'd rather not do (it's less elegant IMO, whatever that's worth). > > Is there a way to do that directly via the CSV API, > > Very doubtful; csv.writer (and reader for that matter) is implemented > in C, doesn't expose a ._file or similar attribute, and has no > .close() or .flush() methods. > The machinery implemented in C, but they are wrapped in Python, and it's a Python file object being passed to the writer, so I thought maybe there was a 'standard' method of exposing file objects in these types of cases that I just wasn't aware of, but it appears not. Thanks for the info! Jason
-- http://mail.python.org/mailman/listinfo/python-list