blob: 616df55ed0cbcdec833d828d71c1e13e2cf3aaa2 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`csv` --- CSV File Reading and Writing
2===========================================
3
4.. module:: csv
5 :synopsis: Write and read tabular data to and from delimited files.
6.. sectionauthor:: Skip Montanaro <skip@pobox.com>
7
Andrew Kuchling2e3743c2014-03-19 16:23:01 -04008**Source code:** :source:`Lib/csv.py`
Georg Brandl116aa622007-08-15 14:28:22 +00009
Georg Brandl116aa622007-08-15 14:28:22 +000010.. index::
11 single: csv
12 pair: data; tabular
13
14The so-called CSV (Comma Separated Values) format is the most common import and
Skip Montanarob40dea72011-03-19 09:09:30 -050015export format for spreadsheets and databases. CSV format was used for many
16years prior to attempts to describe the format in a standardized way in
17:rfc:`4180`. The lack of a well-defined standard means that subtle differences
18often exist in the data produced and consumed by different applications. These
19differences can make it annoying to process CSV files from multiple sources.
20Still, while the delimiters and quoting characters vary, the overall format is
21similar enough that it is possible to write a single module which can
22efficiently manipulate such data, hiding the details of reading and writing the
23data from the programmer.
Georg Brandl116aa622007-08-15 14:28:22 +000024
25The :mod:`csv` module implements classes to read and write tabular data in CSV
26format. It allows programmers to say, "write this data in the format preferred
27by Excel," or "read data from this file which was generated by Excel," without
28knowing the precise details of the CSV format used by Excel. Programmers can
29also describe the CSV formats understood by other applications or define their
30own special-purpose CSV formats.
31
32The :mod:`csv` module's :class:`reader` and :class:`writer` objects read and
33write sequences. Programmers can also read and write data in dictionary form
34using the :class:`DictReader` and :class:`DictWriter` classes.
35
Georg Brandl116aa622007-08-15 14:28:22 +000036.. seealso::
37
Georg Brandl116aa622007-08-15 14:28:22 +000038 :pep:`305` - CSV File API
39 The Python Enhancement Proposal which proposed this addition to Python.
40
41
42.. _csv-contents:
43
44Module Contents
45---------------
46
47The :mod:`csv` module defines the following functions:
48
49
R David Murray1b00f252012-08-15 10:43:58 -040050.. index::
51 single: universal newlines; csv.reader function
52
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000053.. function:: reader(csvfile, dialect='excel', **fmtparams)
Georg Brandl116aa622007-08-15 14:28:22 +000054
55 Return a reader object which will iterate over lines in the given *csvfile*.
Georg Brandl9afde1c2007-11-01 20:32:30 +000056 *csvfile* can be any object which supports the :term:`iterator` protocol and returns a
Georg Brandlb30f3302011-01-06 09:23:56 +000057 string each time its :meth:`!__next__` method is called --- :term:`file objects
Antoine Pitrou11cb9612010-09-15 11:11:28 +000058 <file object>` and list objects are both suitable. If *csvfile* is a file object,
R David Murray91887022011-03-19 22:30:14 -040059 it should be opened with ``newline=''``. [1]_ An optional
Georg Brandl116aa622007-08-15 14:28:22 +000060 *dialect* parameter can be given which is used to define a set of parameters
61 specific to a particular CSV dialect. It may be an instance of a subclass of
62 the :class:`Dialect` class or one of the strings returned by the
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000063 :func:`list_dialects` function. The other optional *fmtparams* keyword arguments
Georg Brandl116aa622007-08-15 14:28:22 +000064 can be given to override individual formatting parameters in the current
65 dialect. For full details about the dialect and formatting parameters, see
66 section :ref:`csv-fmt-params`.
67
Skip Montanaro0468df32009-03-25 00:52:18 +000068 Each row read from the csv file is returned as a list of strings. No
R. David Murray8b7d4aa2009-04-04 01:38:38 +000069 automatic data type conversion is performed unless the ``QUOTE_NONNUMERIC`` format
70 option is specified (in which case unquoted fields are transformed into floats).
Georg Brandl116aa622007-08-15 14:28:22 +000071
Christian Heimesb9eccbf2007-12-05 20:18:38 +000072 A short usage example::
Georg Brandl48310cd2009-01-03 21:18:54 +000073
Christian Heimesb9eccbf2007-12-05 20:18:38 +000074 >>> import csv
Ezio Melottie34f8a92012-09-15 05:51:45 +030075 >>> with open('eggs.csv', newline='') as csvfile:
76 ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
77 ... for row in spamreader:
78 ... print(', '.join(row))
Christian Heimesb9eccbf2007-12-05 20:18:38 +000079 Spam, Spam, Spam, Spam, Spam, Baked Beans
80 Spam, Lovely Spam, Wonderful Spam
81
Georg Brandl116aa622007-08-15 14:28:22 +000082
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000083.. function:: writer(csvfile, dialect='excel', **fmtparams)
Georg Brandl116aa622007-08-15 14:28:22 +000084
85 Return a writer object responsible for converting the user's data into delimited
86 strings on the given file-like object. *csvfile* can be any object with a
R David Murray9c0d5ea2011-03-20 11:18:21 -040087 :func:`write` method. If *csvfile* is a file object, it should be opened with
88 ``newline=''`` [1]_. An optional *dialect*
Georg Brandl116aa622007-08-15 14:28:22 +000089 parameter can be given which is used to define a set of parameters specific to a
90 particular CSV dialect. It may be an instance of a subclass of the
91 :class:`Dialect` class or one of the strings returned by the
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000092 :func:`list_dialects` function. The other optional *fmtparams* keyword arguments
Georg Brandl116aa622007-08-15 14:28:22 +000093 can be given to override individual formatting parameters in the current
94 dialect. For full details about the dialect and formatting parameters, see
95 section :ref:`csv-fmt-params`. To make it
96 as easy as possible to interface with modules which implement the DB API, the
97 value :const:`None` is written as the empty string. While this isn't a
98 reversible transformation, it makes it easier to dump SQL NULL data values to
99 CSV files without preprocessing the data returned from a ``cursor.fetch*`` call.
100 All other non-string data are stringified with :func:`str` before being written.
101
Christian Heimesb9eccbf2007-12-05 20:18:38 +0000102 A short usage example::
103
Ezio Melottie34f8a92012-09-15 05:51:45 +0300104 import csv
105 with open('eggs.csv', 'w', newline='') as csvfile:
106 spamwriter = csv.writer(csvfile, delimiter=' ',
107 quotechar='|', quoting=csv.QUOTE_MINIMAL)
108 spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
109 spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
Christian Heimesb9eccbf2007-12-05 20:18:38 +0000110
Georg Brandl116aa622007-08-15 14:28:22 +0000111
Georg Brandlc2a4f4f2009-04-10 09:03:43 +0000112.. function:: register_dialect(name[, dialect], **fmtparams)
Georg Brandl116aa622007-08-15 14:28:22 +0000113
Georg Brandlf6945182008-02-01 11:56:49 +0000114 Associate *dialect* with *name*. *name* must be a string. The
Georg Brandl116aa622007-08-15 14:28:22 +0000115 dialect can be specified either by passing a sub-class of :class:`Dialect`, or
Georg Brandlc2a4f4f2009-04-10 09:03:43 +0000116 by *fmtparams* keyword arguments, or both, with keyword arguments overriding
Georg Brandl116aa622007-08-15 14:28:22 +0000117 parameters of the dialect. For full details about the dialect and formatting
118 parameters, see section :ref:`csv-fmt-params`.
119
120
121.. function:: unregister_dialect(name)
122
123 Delete the dialect associated with *name* from the dialect registry. An
124 :exc:`Error` is raised if *name* is not a registered dialect name.
125
126
127.. function:: get_dialect(name)
128
Georg Brandl6554cb92007-12-02 23:15:43 +0000129 Return the dialect associated with *name*. An :exc:`Error` is raised if
130 *name* is not a registered dialect name. This function returns an immutable
131 :class:`Dialect`.
Georg Brandl116aa622007-08-15 14:28:22 +0000132
133.. function:: list_dialects()
134
135 Return the names of all registered dialects.
136
137
138.. function:: field_size_limit([new_limit])
139
140 Returns the current maximum field size allowed by the parser. If *new_limit* is
141 given, this becomes the new limit.
142
Georg Brandl116aa622007-08-15 14:28:22 +0000143
144The :mod:`csv` module defines the following classes:
145
R David Murrayf031a6f2014-02-24 15:32:54 -0500146.. class:: DictReader(csvfile, fieldnames=None, restkey=None, restval=None, \
147 dialect='excel', *args, **kwds)
Georg Brandl116aa622007-08-15 14:28:22 +0000148
R David Murrayf031a6f2014-02-24 15:32:54 -0500149 Create an object which operates like a regular reader but maps the
150 information read into a dict whose keys are given by the optional
151 *fieldnames* parameter. The *fieldnames* parameter is a :mod:`sequence
152 <collections.abc>` whose elements are associated with the fields of the
153 input data in order. These elements become the keys of the resulting
154 dictionary. If the *fieldnames* parameter is omitted, the values in the
155 first row of the *csvfile* will be used as the fieldnames. If the row read
156 has more fields than the fieldnames sequence, the remaining data is added as
157 a sequence keyed by the value of *restkey*. If the row read has fewer
158 fields than the fieldnames sequence, the remaining keys take the value of
159 the optional *restval* parameter. Any other optional or keyword arguments
160 are passed to the underlying :class:`reader` instance.
Georg Brandl116aa622007-08-15 14:28:22 +0000161
162
R David Murrayf031a6f2014-02-24 15:32:54 -0500163.. class:: DictWriter(csvfile, fieldnames, restval='', extrasaction='raise', \
164 dialect='excel', *args, **kwds)
Georg Brandl116aa622007-08-15 14:28:22 +0000165
R David Murrayf031a6f2014-02-24 15:32:54 -0500166 Create an object which operates like a regular writer but maps dictionaries
167 onto output rows. The *fieldnames* parameter is a :mod:`sequence
168 <collections.abc>` of keys that identify the order in which values in the
169 dictionary passed to the :meth:`writerow` method are written to the
170 *csvfile*. The optional *restval* parameter specifies the value to be
171 written if the dictionary is missing a key in *fieldnames*. If the
172 dictionary passed to the :meth:`writerow` method contains a key not found in
173 *fieldnames*, the optional *extrasaction* parameter indicates what action to
174 take. If it is set to ``'raise'`` a :exc:`ValueError` is raised. If it is
175 set to ``'ignore'``, extra values in the dictionary are ignored. Any other
176 optional or keyword arguments are passed to the underlying :class:`writer`
177 instance.
Georg Brandl116aa622007-08-15 14:28:22 +0000178
R David Murrayf031a6f2014-02-24 15:32:54 -0500179 Note that unlike the :class:`DictReader` class, the *fieldnames* parameter
180 of the :class:`DictWriter` is not optional. Since Python's :class:`dict`
181 objects are not ordered, there is not enough information available to deduce
182 the order in which the row should be written to the *csvfile*.
Georg Brandl116aa622007-08-15 14:28:22 +0000183
184
185.. class:: Dialect
186
187 The :class:`Dialect` class is a container class relied on primarily for its
188 attributes, which are used to define the parameters for a specific
189 :class:`reader` or :class:`writer` instance.
190
191
192.. class:: excel()
193
194 The :class:`excel` class defines the usual properties of an Excel-generated CSV
195 file. It is registered with the dialect name ``'excel'``.
196
197
198.. class:: excel_tab()
199
200 The :class:`excel_tab` class defines the usual properties of an Excel-generated
201 TAB-delimited file. It is registered with the dialect name ``'excel-tab'``.
202
203
Georg Brandl7424dd32010-10-27 07:27:06 +0000204.. class:: unix_dialect()
205
206 The :class:`unix_dialect` class defines the usual properties of a CSV file
207 generated on UNIX systems, i.e. using ``'\n'`` as line terminator and quoting
208 all fields. It is registered with the dialect name ``'unix'``.
209
210 .. versionadded:: 3.2
211
212
Georg Brandl116aa622007-08-15 14:28:22 +0000213.. class:: Sniffer()
214
215 The :class:`Sniffer` class is used to deduce the format of a CSV file.
216
Benjamin Petersone41251e2008-04-25 01:59:09 +0000217 The :class:`Sniffer` class provides two methods:
Georg Brandl116aa622007-08-15 14:28:22 +0000218
Georg Brandlc2a4f4f2009-04-10 09:03:43 +0000219 .. method:: sniff(sample, delimiters=None)
Georg Brandl116aa622007-08-15 14:28:22 +0000220
Benjamin Petersone41251e2008-04-25 01:59:09 +0000221 Analyze the given *sample* and return a :class:`Dialect` subclass
222 reflecting the parameters found. If the optional *delimiters* parameter
223 is given, it is interpreted as a string containing possible valid
224 delimiter characters.
Georg Brandl116aa622007-08-15 14:28:22 +0000225
226
Benjamin Petersone41251e2008-04-25 01:59:09 +0000227 .. method:: has_header(sample)
Georg Brandl116aa622007-08-15 14:28:22 +0000228
Benjamin Petersone41251e2008-04-25 01:59:09 +0000229 Analyze the sample text (presumed to be in CSV format) and return
230 :const:`True` if the first row appears to be a series of column headers.
Georg Brandl116aa622007-08-15 14:28:22 +0000231
Christian Heimes7f044312008-01-06 17:05:40 +0000232An example for :class:`Sniffer` use::
Georg Brandl116aa622007-08-15 14:28:22 +0000233
Ezio Melottie34f8a92012-09-15 05:51:45 +0300234 with open('example.csv') as csvfile:
235 dialect = csv.Sniffer().sniff(csvfile.read(1024))
236 csvfile.seek(0)
237 reader = csv.reader(csvfile, dialect)
238 # ... process CSV file contents here ...
Christian Heimes7f044312008-01-06 17:05:40 +0000239
240
241The :mod:`csv` module defines the following constants:
Georg Brandl116aa622007-08-15 14:28:22 +0000242
243.. data:: QUOTE_ALL
244
245 Instructs :class:`writer` objects to quote all fields.
246
247
248.. data:: QUOTE_MINIMAL
249
250 Instructs :class:`writer` objects to only quote those fields which contain
251 special characters such as *delimiter*, *quotechar* or any of the characters in
252 *lineterminator*.
253
254
255.. data:: QUOTE_NONNUMERIC
256
257 Instructs :class:`writer` objects to quote all non-numeric fields.
258
259 Instructs the reader to convert all non-quoted fields to type *float*.
260
261
262.. data:: QUOTE_NONE
263
264 Instructs :class:`writer` objects to never quote fields. When the current
265 *delimiter* occurs in output data it is preceded by the current *escapechar*
266 character. If *escapechar* is not set, the writer will raise :exc:`Error` if
267 any characters that require escaping are encountered.
268
269 Instructs :class:`reader` to perform no special processing of quote characters.
270
271The :mod:`csv` module defines the following exception:
272
273
274.. exception:: Error
275
276 Raised by any of the functions when an error is detected.
277
Georg Brandl116aa622007-08-15 14:28:22 +0000278.. _csv-fmt-params:
279
280Dialects and Formatting Parameters
281----------------------------------
282
283To make it easier to specify the format of input and output records, specific
284formatting parameters are grouped together into dialects. A dialect is a
285subclass of the :class:`Dialect` class having a set of specific methods and a
286single :meth:`validate` method. When creating :class:`reader` or
287:class:`writer` objects, the programmer can specify a string or a subclass of
288the :class:`Dialect` class as the dialect parameter. In addition to, or instead
289of, the *dialect* parameter, the programmer can also specify individual
290formatting parameters, which have the same names as the attributes defined below
291for the :class:`Dialect` class.
292
293Dialects support the following attributes:
294
295
296.. attribute:: Dialect.delimiter
297
298 A one-character string used to separate fields. It defaults to ``','``.
299
300
301.. attribute:: Dialect.doublequote
302
303 Controls how instances of *quotechar* appearing inside a field should be
304 themselves be quoted. When :const:`True`, the character is doubled. When
305 :const:`False`, the *escapechar* is used as a prefix to the *quotechar*. It
306 defaults to :const:`True`.
307
308 On output, if *doublequote* is :const:`False` and no *escapechar* is set,
309 :exc:`Error` is raised if a *quotechar* is found in a field.
310
311
312.. attribute:: Dialect.escapechar
313
314 A one-character string used by the writer to escape the *delimiter* if *quoting*
315 is set to :const:`QUOTE_NONE` and the *quotechar* if *doublequote* is
316 :const:`False`. On reading, the *escapechar* removes any special meaning from
317 the following character. It defaults to :const:`None`, which disables escaping.
318
319
320.. attribute:: Dialect.lineterminator
321
322 The string used to terminate lines produced by the :class:`writer`. It defaults
323 to ``'\r\n'``.
324
325 .. note::
326
327 The :class:`reader` is hard-coded to recognise either ``'\r'`` or ``'\n'`` as
328 end-of-line, and ignores *lineterminator*. This behavior may change in the
329 future.
330
331
332.. attribute:: Dialect.quotechar
333
334 A one-character string used to quote fields containing special characters, such
335 as the *delimiter* or *quotechar*, or which contain new-line characters. It
336 defaults to ``'"'``.
337
338
339.. attribute:: Dialect.quoting
340
341 Controls when quotes should be generated by the writer and recognised by the
342 reader. It can take on any of the :const:`QUOTE_\*` constants (see section
343 :ref:`csv-contents`) and defaults to :const:`QUOTE_MINIMAL`.
344
345
346.. attribute:: Dialect.skipinitialspace
347
348 When :const:`True`, whitespace immediately following the *delimiter* is ignored.
349 The default is :const:`False`.
350
351
Ezio Melottia69be282012-11-18 12:55:35 +0200352.. attribute:: Dialect.strict
353
354 When ``True``, raise exception :exc:`Error` on bad CSV input.
355 The default is ``False``.
356
Georg Brandl116aa622007-08-15 14:28:22 +0000357Reader Objects
358--------------
359
360Reader objects (:class:`DictReader` instances and objects returned by the
361:func:`reader` function) have the following public methods:
362
Georg Brandlc7485062009-04-01 15:53:15 +0000363.. method:: csvreader.__next__()
Georg Brandl116aa622007-08-15 14:28:22 +0000364
365 Return the next row of the reader's iterable object as a list, parsed according
Georg Brandlc7485062009-04-01 15:53:15 +0000366 to the current dialect. Usually you should call this as ``next(reader)``.
367
Georg Brandl116aa622007-08-15 14:28:22 +0000368
369Reader objects have the following public attributes:
370
Georg Brandl116aa622007-08-15 14:28:22 +0000371.. attribute:: csvreader.dialect
372
373 A read-only description of the dialect in use by the parser.
374
375
376.. attribute:: csvreader.line_num
377
378 The number of lines read from the source iterator. This is not the same as the
379 number of records returned, as records can span multiple lines.
380
Georg Brandl116aa622007-08-15 14:28:22 +0000381
Skip Montanaroaf8fcfa2008-08-09 19:44:22 +0000382DictReader objects have the following public attribute:
383
Skip Montanaroaf8fcfa2008-08-09 19:44:22 +0000384.. attribute:: csvreader.fieldnames
385
386 If not passed as a parameter when creating the object, this attribute is
387 initialized upon first access or when the first record is read from the
388 file.
389
Skip Montanaroaf8fcfa2008-08-09 19:44:22 +0000390
391
Georg Brandl116aa622007-08-15 14:28:22 +0000392Writer Objects
393--------------
394
395:class:`Writer` objects (:class:`DictWriter` instances and objects returned by
396the :func:`writer` function) have the following public methods. A *row* must be
397a sequence of strings or numbers for :class:`Writer` objects and a dictionary
398mapping fieldnames to strings or numbers (by passing them through :func:`str`
399first) for :class:`DictWriter` objects. Note that complex numbers are written
400out surrounded by parens. This may cause some problems for other programs which
401read CSV files (assuming they support complex numbers at all).
402
403
404.. method:: csvwriter.writerow(row)
405
406 Write the *row* parameter to the writer's file object, formatted according to
407 the current dialect.
408
409
410.. method:: csvwriter.writerows(rows)
411
412 Write all the *rows* parameters (a list of *row* objects as described above) to
413 the writer's file object, formatted according to the current dialect.
414
415Writer objects have the following public attribute:
416
417
418.. attribute:: csvwriter.dialect
419
420 A read-only description of the dialect in use by the writer.
421
422
R. David Murraybe0698b2010-02-23 22:57:58 +0000423DictWriter objects have the following public method:
424
425
426.. method:: DictWriter.writeheader()
427
428 Write a row with the field names (as specified in the constructor).
429
R. David Murray19e45482010-02-23 23:00:34 +0000430 .. versionadded:: 3.2
R. David Murraybe0698b2010-02-23 22:57:58 +0000431
432
Georg Brandl116aa622007-08-15 14:28:22 +0000433.. _csv-examples:
434
435Examples
436--------
437
438The simplest example of reading a CSV file::
439
440 import csv
Eli Bendersky6860a922011-03-11 15:47:36 +0200441 with open('some.csv', newline='') as f:
442 reader = csv.reader(f)
443 for row in reader:
444 print(row)
Georg Brandl116aa622007-08-15 14:28:22 +0000445
446Reading a file with an alternate format::
447
448 import csv
R David Murray91887022011-03-19 22:30:14 -0400449 with open('passwd', newline='') as f:
Eli Bendersky6860a922011-03-11 15:47:36 +0200450 reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
451 for row in reader:
452 print(row)
Georg Brandl116aa622007-08-15 14:28:22 +0000453
454The corresponding simplest possible writing example is::
455
456 import csv
R David Murray91887022011-03-19 22:30:14 -0400457 with open('some.csv', 'w', newline='') as f:
Eli Bendersky6860a922011-03-11 15:47:36 +0200458 writer = csv.writer(f)
459 writer.writerows(someiterable)
Georg Brandl116aa622007-08-15 14:28:22 +0000460
R. David Murray8b7d4aa2009-04-04 01:38:38 +0000461Since :func:`open` is used to open a CSV file for reading, the file
462will by default be decoded into unicode using the system default
463encoding (see :func:`locale.getpreferredencoding`). To decode a file
464using a different encoding, use the ``encoding`` argument of open::
465
Eli Bendersky6860a922011-03-11 15:47:36 +0200466 import csv
467 with open('some.csv', newline='', encoding='utf-8') as f:
468 reader = csv.reader(f)
469 for row in reader:
470 print(row)
R. David Murray8b7d4aa2009-04-04 01:38:38 +0000471
472The same applies to writing in something other than the system default
473encoding: specify the encoding argument when opening the output file.
474
Georg Brandl116aa622007-08-15 14:28:22 +0000475Registering a new dialect::
476
477 import csv
Georg Brandl116aa622007-08-15 14:28:22 +0000478 csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
R David Murray91887022011-03-19 22:30:14 -0400479 with open('passwd', newline='') as f:
Eli Bendersky6860a922011-03-11 15:47:36 +0200480 reader = csv.reader(f, 'unixpwd')
Georg Brandl116aa622007-08-15 14:28:22 +0000481
482A slightly more advanced use of the reader --- catching and reporting errors::
483
484 import csv, sys
Eli Bendersky6860a922011-03-11 15:47:36 +0200485 filename = 'some.csv'
486 with open(filename, newline='') as f:
487 reader = csv.reader(f)
488 try:
489 for row in reader:
490 print(row)
491 except csv.Error as e:
492 sys.exit('file {}, line {}: {}'.format(filename, reader.line_num, e))
Georg Brandl116aa622007-08-15 14:28:22 +0000493
494And while the module doesn't directly support parsing strings, it can easily be
495done::
496
497 import csv
498 for row in csv.reader(['one,two,three']):
Georg Brandl6911e3c2007-09-04 07:15:32 +0000499 print(row)
Georg Brandl116aa622007-08-15 14:28:22 +0000500
Georg Brandl116aa622007-08-15 14:28:22 +0000501
R. David Murray8b7d4aa2009-04-04 01:38:38 +0000502.. rubric:: Footnotes
Georg Brandl116aa622007-08-15 14:28:22 +0000503
R David Murray91887022011-03-19 22:30:14 -0400504.. [1] If ``newline=''`` is not specified, newlines embedded inside quoted fields
505 will not be interpreted correctly, and on platforms that use ``\r\n`` linendings
R David Murray9c0d5ea2011-03-20 11:18:21 -0400506 on write an extra ``\r`` will be added. It should always be safe to specify
R David Murray1b00f252012-08-15 10:43:58 -0400507 ``newline=''``, since the csv module does its own
508 (:term:`universal <universal newlines>`) newline handling.