[Python-checkins] cpython (merge 3.2 -> default): #15932: merge with 3.2.

ezio.melotti python-checkins at python.org
Sat Sep 15 04:52:55 CEST 2012


http://hg.python.org/cpython/rev/a5a8d255daee
changeset:   79031:a5a8d255daee
parent:      79027:3b0e20f71d8a
parent:      79030:8a06fb321074
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat Sep 15 05:52:36 2012 +0300
summary:
  #15932: merge with 3.2.

files:
  Doc/library/csv.rst |  28 +++++++++++++++-------------
  1 files changed, 15 insertions(+), 13 deletions(-)


diff --git a/Doc/library/csv.rst b/Doc/library/csv.rst
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -71,9 +71,10 @@
    A short usage example::
 
       >>> import csv
-      >>> spamReader = csv.reader(open('eggs.csv', newline=''), delimiter=' ', quotechar='|')
-      >>> for row in spamReader:
-      ...     print(', '.join(row))
+      >>> with open('eggs.csv', newline='') as csvfile:
+      ...     spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
+      ...     for row in spamreader:
+      ...         print(', '.join(row))
       Spam, Spam, Spam, Spam, Spam, Baked Beans
       Spam, Lovely Spam, Wonderful Spam
 
@@ -99,11 +100,12 @@
 
    A short usage example::
 
-      >>> import csv
-      >>> spamWriter = csv.writer(open('eggs.csv', 'w', newline=''), delimiter=' ',
-      ...                         quotechar='|', quoting=csv.QUOTE_MINIMAL)
-      >>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans'])
-      >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
+      import csv
+      with open('eggs.csv', 'w', newline='') as csvfile:
+          spamwriter = csv.writer(csvfile, delimiter=' ',
+                                  quotechar='|', quoting=csv.QUOTE_MINIMAL)
+          spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
+          spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
 
 
 .. function:: register_dialect(name[, dialect], **fmtparams)
@@ -221,11 +223,11 @@
 
 An example for :class:`Sniffer` use::
 
-   csvfile = open("example.csv")
-   dialect = csv.Sniffer().sniff(csvfile.read(1024))
-   csvfile.seek(0)
-   reader = csv.reader(csvfile, dialect)
-   # ... process CSV file contents here ...
+   with open('example.csv') as csvfile:
+       dialect = csv.Sniffer().sniff(csvfile.read(1024))
+       csvfile.seek(0)
+       reader = csv.reader(csvfile, dialect)
+       # ... process CSV file contents here ...
 
 
 The :mod:`csv` module defines the following constants:

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


More information about the Python-checkins mailing list