[Python-checkins] python/dist/src/Doc/lib libcsv.tex,1.9,1.10

montanaro at users.sourceforge.net montanaro at users.sourceforge.net
Fri Oct 3 10:03:03 EDT 2003


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv20930/Doc/lib

Modified Files:
	libcsv.tex 
Log Message:
Make the fieldnames argument optional in the DictReader.  If self.fieldnames
is None, the next row read is used as the fieldnames.  In the common case,
this means the programmer doesn't need to know the fieldnames ahead of time.
The first row of the file will be used.  In the uncommon case, this means
the programmer can set the reader's fieldnames attribute to None at any time
and have the next row read as the next set of fieldnames, so a csv file can
contain several "sections", each with different fieldnames.



Index: libcsv.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/libcsv.tex,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** libcsv.tex	10 Sep 2003 18:54:49 -0000	1.9
--- libcsv.tex	3 Oct 2003 14:03:01 -0000	1.10
***************
*** 118,129 ****
  The \module{csv} module defines the following classes:
  
! \begin{classdesc}{DictReader}{csvfile, fieldnames\optional{,
                                restkey=\constant{None}\optional{,
  			      restval=\constant{None}\optional{,
                                dialect=\code{'excel'}\optional{,
! 			      fmtparam}}}}}
  Create an object which operates like a regular reader but maps the
! information read into a dict whose keys are given by the \var{fieldnames}
! parameter.  If the row read has fewer fields than the fieldnames sequence,
  the value of \var{restval} will be used as the default value.  If the row
  read has more fields than the fieldnames sequence, the remaining data is
--- 118,133 ----
  The \module{csv} module defines the following classes:
  
! \begin{classdesc}{DictReader}{csvfile\optional{,
! 			      fieldnames=\constant{None},\optional{,
                                restkey=\constant{None}\optional{,
  			      restval=\constant{None}\optional{,
                                dialect=\code{'excel'}\optional{,
! 			      fmtparam}}}}}}
  Create an object which operates like a regular reader but maps the
! information read into a dict whose keys are given by the optional
! {} \var{fieldnames}
! parameter.  If the \var{fieldnames} parameter is omitted, the values in
! the first row of the \var{csvfile} will be used as the fieldnames.
! If the row read has fewer fields than the fieldnames sequence,
  the value of \var{restval} will be used as the default value.  If the row
  read has more fields than the fieldnames sequence, the remaining data is
***************
*** 150,153 ****
--- 154,164 ----
  \code{'ignore'}, extra values in the dictionary are ignored.  All other
  parameters are interpreted as for \class{writer} objects.
+ 
+ Note that unlike the \class{DictReader} class, the \var{fieldnames}
+ parameter of the \class{DictWriter} is not optional.  Since Python's
+ \class{dict} objects are not ordered, there is not enough information
+ available to deduce the order in which the row should be written to the
+ \var{csvfile}.
+ 
  \end{classdesc}
  





More information about the Python-checkins mailing list