[Python-checkins] Issue #11426: use 'with' statements on open files in CSV examples (original) (raw)

eli.bendersky python-checkins at python.org
Fri Mar 11 14:47:42 CET 2011


http://hg.python.org/cpython/rev/f2a73d65422a changeset: 68369:f2a73d65422a user: Eli Bendersky <eliben at gmail.com> date: Fri Mar 11 15:47:36 2011 +0200 summary: Issue #11426: use 'with' statements on open files in CSV examples

files: Doc/library/csv.rst

diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst --- a/Doc/library/csv.rst +++ b/Doc/library/csv.rst @@ -419,32 +419,36 @@ The simplest example of reading a CSV file::

import csv

Reading a file with an alternate format::

import csv

The corresponding simplest possible writing example is::

import csv

Since :func:open is used to open a CSV file for reading, the file will by default be decoded into unicode using the system default encoding (see :func:locale.getpreferredencoding). To decode a file using a different encoding, use the encoding argument of open::

The same applies to writing in something other than the system default encoding: specify the encoding argument when opening the output file. @@ -453,18 +457,20 @@

import csv
csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)

A slightly more advanced use of the reader --- catching and reporting errors::

import csv, sys

And while the module doesn't directly support parsing strings, it can easily be done::

-- Repository URL: http://hg.python.org/cpython



More information about the Python-checkins mailing list