CSV writer question

Andrew McLean lists at andros.org.uk
Mon Oct 24 16:35:13 EDT 2011


On 24/10/2011 08:03, Chris Angelico wrote:
> On Mon, Oct 24, 2011 at 4:18 PM, Jason Swails<jason.swails at gmail.com>  wrote:
>> my_csv = csv.writer(open('temp.1.csv', 'wb'))
>>
> Have you confirmed, or can you confirm, whether or not the file gets
> closed automatically when the writer gets destructed? If so, all you
> need to do is:
>
> my_csv = something_else
> # or:
> del my_csv
>
> to unbind what I assume is the only reference to the csv.writer, upon
> which it should promptly clean itself up.
My understanding is that in cpython the file does get closed when the 
writer is deleted, however, it's not guaranteed to happen in other 
Python implementations (e.g. IronPython, PyPy and Jython).

Andrew




More information about the Python-list mailing list