cpython: fa0563f3b7f7 (original) (raw)
--- a/Doc/library/csv.rst
+++ b/Doc/library/csv.rst
@@ -52,7 +52,7 @@ The :mod:csv
module defines the follow
csvfile can be any object which supports the :term:iterator
protocol and returns a
string each time its :meth:!__next__
method is called --- :term:file objects[](#l1.5) <file object>
and list objects are both suitable. If csvfile is a file object,
- it should be opened with
newline=''
. [1]_ An optional dialect parameter can be given which is used to define a set of parameters specific to a particular CSV dialect. It may be an instance of a subclass of the :class:Dialect
class or one of the strings returned by the @@ -79,7 +79,8 @@ The :mod:csv
module defines the follow Return a writer object responsible for converting the user's data into delimited strings on the given file-like object. csvfile can be any object with a
- :func:
write
method. If csvfile is a file object, it should be opened with - newline='' [1]_. An optional dialect
parameter can be given which is used to define a set of parameters specific to a
particular CSV dialect. It may be an instance of a subclass of the
:class:
Dialect
class or one of the strings returned by the @@ -96,7 +97,7 @@ The :mod:csv
module defines the follow A short usage example::
>>> spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ',[](#l1.26)
>>> spamWriter = csv.writer(open('eggs.csv', 'w', newline=''), delimiter=' ',[](#l1.27) ... quotechar='|', quoting=csv.QUOTE_MINIMAL)[](#l1.28) >>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans'])[](#l1.29) >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])[](#l1.30)
@@ -427,7 +428,7 @@ The simplest example of reading a CSV fi Reading a file with an alternate format:: import csv
- with open('passwd', newline='') as f: reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE) for row in reader: print(row)
@@ -435,7 +436,7 @@ Reading a file with an alternate format: The corresponding simplest possible writing example is:: import csv
@@ -457,7 +458,7 @@ Registering a new dialect:: import csv csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
A slightly more advanced use of the reader --- catching and reporting errors::
@@ -482,7 +483,7 @@ done::
.. rubric:: Footnotes
-.. [#] If newline=''
is not specified, newlines embedded inside quoted fields