~ubuntu-branches/debian/sid/python3.3/sid

« back to all changes in this revision

Viewing changes to Doc/library/csv.rst

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-05 08:32:07 UTC
  • mfrom: (1.2.14)
  • Revision ID: package-import@ubuntu.com-20140305083207-8whtoqkk2rso4f2b
Tags: 3.3.5~rc2-1
* Python 3.3.5 release candidate 2.
* Build without ffi on or1k. Addresses: #738519.
* Allow loading of extensions in the sqlite module. Addresses: #739555.
* Update autopkg tests (Martin Pitt):
  - Don't fail if apport is not installed.
  - Call su with explicit shell, as nobody has nologin as default shell now.
  - Only use $SUDO_USER if that user actually exists in the testbed.
  - Drop obsolete chowning of $TMPDIR and $ADTTMP; with current autopkgtest
    $TMPDIR has appropriate permissions, and $ADTTMP is not being used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
 
143
143
The :mod:`csv` module defines the following classes:
144
144
 
145
 
.. class:: DictReader(csvfile, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)
146
 
 
147
 
   Create an object which operates like a regular reader but maps the information
148
 
   read into a dict whose keys are given by the optional  *fieldnames* parameter.
149
 
   If the *fieldnames* parameter is omitted, the values in the first row of the
150
 
   *csvfile* will be used as the fieldnames.  If the row read has more fields
151
 
   than the fieldnames sequence, the remaining data is added as a sequence
152
 
   keyed by the value of *restkey*.  If the row read has fewer fields than the
153
 
   fieldnames sequence, the remaining keys take the value of the optional
154
 
   *restval* parameter.  Any other optional or keyword arguments are passed to
155
 
   the underlying :class:`reader` instance.
156
 
 
157
 
 
158
 
.. class:: DictWriter(csvfile, fieldnames, restval='', extrasaction='raise', dialect='excel', *args, **kwds)
159
 
 
160
 
   Create an object which operates like a regular writer but maps dictionaries onto
161
 
   output rows.  The *fieldnames* parameter identifies the order in which values in
162
 
   the dictionary passed to the :meth:`writerow` method are written to the
163
 
   *csvfile*.  The optional *restval* parameter specifies the value to be written
164
 
   if the dictionary is missing a key in *fieldnames*.  If the dictionary passed to
165
 
   the :meth:`writerow` method contains a key not found in *fieldnames*, the
166
 
   optional *extrasaction* parameter indicates what action to take.  If it is set
167
 
   to ``'raise'`` a :exc:`ValueError` is raised.  If it is set to ``'ignore'``,
168
 
   extra values in the dictionary are ignored.  Any other optional or keyword
169
 
   arguments are passed to the underlying :class:`writer` instance.
170
 
 
171
 
   Note that unlike the :class:`DictReader` class, the *fieldnames* parameter of
172
 
   the :class:`DictWriter` is not optional.  Since Python's :class:`dict` objects
173
 
   are not ordered, there is not enough information available to deduce the order
174
 
   in which the row should be written to the *csvfile*.
 
145
.. class:: DictReader(csvfile, fieldnames=None, restkey=None, restval=None, \
 
146
                      dialect='excel', *args, **kwds)
 
147
 
 
148
   Create an object which operates like a regular reader but maps the
 
149
   information read into a dict whose keys are given by the optional
 
150
   *fieldnames* parameter.  The *fieldnames* parameter is a :mod:`sequence
 
151
   <collections.abc>` whose elements are associated with the fields of the
 
152
   input data in order. These elements become the keys of the resulting
 
153
   dictionary.  If the *fieldnames* parameter is omitted, the values in the
 
154
   first row of the *csvfile* will be used as the fieldnames.  If the row read
 
155
   has more fields than the fieldnames sequence, the remaining data is added as
 
156
   a sequence keyed by the value of *restkey*.  If the row read has fewer
 
157
   fields than the fieldnames sequence, the remaining keys take the value of
 
158
   the optional *restval* parameter.  Any other optional or keyword arguments
 
159
   are passed to the underlying :class:`reader` instance.
 
160
 
 
161
 
 
162
.. class:: DictWriter(csvfile, fieldnames, restval='', extrasaction='raise', \
 
163
                      dialect='excel', *args, **kwds)
 
164
 
 
165
   Create an object which operates like a regular writer but maps dictionaries
 
166
   onto output rows.  The *fieldnames* parameter is a :mod:`sequence
 
167
   <collections.abc>` of keys that identify the order in which values in the
 
168
   dictionary passed to the :meth:`writerow` method are written to the
 
169
   *csvfile*.  The optional *restval* parameter specifies the value to be
 
170
   written if the dictionary is missing a key in *fieldnames*.  If the
 
171
   dictionary passed to the :meth:`writerow` method contains a key not found in
 
172
   *fieldnames*, the optional *extrasaction* parameter indicates what action to
 
173
   take.  If it is set to ``'raise'`` a :exc:`ValueError` is raised.  If it is
 
174
   set to ``'ignore'``, extra values in the dictionary are ignored.  Any other
 
175
   optional or keyword arguments are passed to the underlying :class:`writer`
 
176
   instance.
 
177
 
 
178
   Note that unlike the :class:`DictReader` class, the *fieldnames* parameter
 
179
   of the :class:`DictWriter` is not optional.  Since Python's :class:`dict`
 
180
   objects are not ordered, there is not enough information available to deduce
 
181
   the order in which the row should be written to the *csvfile*.
175
182
 
176
183
 
177
184
.. class:: Dialect