[docs] Examples in "13.1. csv — CSV File Reading and Writing" don't close files
Sandro Tosi
sandro.tosi at gmail.com
Mon Feb 28 21:23:09 CET 2011
Hi Neil,
thanks for your email.
On Tue, Feb 8, 2011 at 11:01, Neil Vass <neil.vass at gmail.com> wrote:
> Hi,
> I have a suggestion for the csv module's documentation. The examples
> in http://docs.python.org/library/csv.html show file reading like this:
> reader = csv.reader(open("some.csv", "rb"))
> This leaves the file handle open after use, without a way to close it. A
> better example might be
> ifile = open("some.csv", "rb")
> reader = csv.reader(ifile)
> ... process file ...
> ifile.close()
I can see your point, and f.e. in Python3 I'd rather use the with
statement to open the file, but I fear that reformatting the examples
as you propose will make them too big and they'll loose their
compactness and easy-to-get-to-the-point. Maybe a warning at the
beginning of the examples section that they are just \examples\ and so
file handling is not done in a state-of-the-art manner? What other
readers of docs@ think?
Cheers,
--
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
More information about the docs
mailing list