CSV writer question

Jason Swails jason.swails at gmail.com
Mon Oct 24 15:41:31 EDT 2011


On Mon, Oct 24, 2011 at 2:08 AM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Sun, Oct 23, 2011 at 10:18 PM, Jason Swails <jason.swails at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111024/c5d4fbda/attachment-0001.html>


More information about the Python-list mailing list