Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 1 | \section{\module{csv} --- CSV File Reading and Writing} |
| 2 | |
| 3 | \declaremodule{standard}{csv} |
| 4 | \modulesynopsis{Write and read tabular data to and from delimited files.} |
Skip Montanaro | 3bd3c84 | 2003-04-24 18:47:31 +0000 | [diff] [blame] | 5 | \sectionauthor{Skip Montanaro}{skip@pobox.com} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 6 | |
| 7 | \versionadded{2.3} |
| 8 | \index{csv} |
| 9 | \indexii{data}{tabular} |
| 10 | |
| 11 | The so-called CSV (Comma Separated Values) format is the most common import |
| 12 | and export format for spreadsheets and databases. There is no ``CSV |
| 13 | standard'', so the format is operationally defined by the many applications |
| 14 | which read and write it. The lack of a standard means that subtle |
| 15 | differences often exist in the data produced and consumed by different |
| 16 | applications. These differences can make it annoying to process CSV files |
| 17 | from multiple sources. Still, while the delimiters and quoting characters |
| 18 | vary, the overall format is similar enough that it is possible to write a |
| 19 | single module which can efficiently manipulate such data, hiding the details |
| 20 | of reading and writing the data from the programmer. |
| 21 | |
Skip Montanaro | 5d0136e | 2003-04-25 15:14:49 +0000 | [diff] [blame] | 22 | The \module{csv} module implements classes to read and write tabular data in |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 23 | CSV format. It allows programmers to say, ``write this data in the format |
| 24 | preferred by Excel,'' or ``read data from this file which was generated by |
| 25 | Excel,'' without knowing the precise details of the CSV format used by |
| 26 | Excel. Programmers can also describe the CSV formats understood by other |
| 27 | applications or define their own special-purpose CSV formats. |
| 28 | |
Skip Montanaro | 5d0136e | 2003-04-25 15:14:49 +0000 | [diff] [blame] | 29 | The \module{csv} module's \class{reader} and \class{writer} objects read and |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 30 | write sequences. Programmers can also read and write data in dictionary |
| 31 | form using the \class{DictReader} and \class{DictWriter} classes. |
| 32 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 33 | \begin{notice} |
| 34 | This version of the \module{csv} module doesn't support Unicode |
| 35 | input. Also, there are currently some issues regarding \ASCII{} NUL |
| 36 | characters. Accordingly, all input should generally be printable |
| 37 | \ASCII{} to be safe. These restrictions will be removed in the future. |
| 38 | \end{notice} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 39 | |
| 40 | \begin{seealso} |
| 41 | % \seemodule{array}{Arrays of uniformly types numeric values.} |
| 42 | \seepep{305}{CSV File API} |
| 43 | {The Python Enhancement Proposal which proposed this addition |
| 44 | to Python.} |
| 45 | \end{seealso} |
| 46 | |
| 47 | |
Raymond Hettinger | 6f6d7b93 | 2003-08-31 05:44:54 +0000 | [diff] [blame] | 48 | \subsection{Module Contents \label{csv-contents}} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 49 | |
Skip Montanaro | 5d0136e | 2003-04-25 15:14:49 +0000 | [diff] [blame] | 50 | The \module{csv} module defines the following functions: |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 51 | |
| 52 | \begin{funcdesc}{reader}{csvfile\optional{, |
| 53 | dialect=\code{'excel'}\optional{, fmtparam}}} |
| 54 | Return a reader object which will iterate over lines in the given |
| 55 | {}\var{csvfile}. \var{csvfile} can be any object which supports the |
| 56 | iterator protocol and returns a string each time its \method{next} |
Skip Montanaro | 5e4e39f | 2003-07-02 15:32:48 +0000 | [diff] [blame] | 57 | method is called. If \var{csvfile} is a file object, it must be opened with |
| 58 | the 'b' flag on platforms where that makes a difference. An optional |
| 59 | {}\var{dialect} parameter can be given |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 60 | which is used to define a set of parameters specific to a particular CSV |
| 61 | dialect. It may be an instance of a subclass of the \class{Dialect} |
| 62 | class or one of the strings returned by the \function{list_dialects} |
| 63 | function. The other optional {}\var{fmtparam} keyword arguments can be |
| 64 | given to override individual formatting parameters in the current |
| 65 | dialect. For more information about the dialect and formatting |
Raymond Hettinger | 6e380cd | 2003-09-10 18:54:49 +0000 | [diff] [blame] | 66 | parameters, see section~\ref{csv-fmt-params}, ``Dialects and Formatting |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 67 | Parameters'' for details of these parameters. |
| 68 | |
| 69 | All data read are returned as strings. No automatic data type |
| 70 | conversion is performed. |
| 71 | \end{funcdesc} |
| 72 | |
| 73 | \begin{funcdesc}{writer}{csvfile\optional{, |
| 74 | dialect=\code{'excel'}\optional{, fmtparam}}} |
| 75 | Return a writer object responsible for converting the user's data into |
Skip Montanaro | 5e4e39f | 2003-07-02 15:32:48 +0000 | [diff] [blame] | 76 | delimited strings on the given file-like object. \var{csvfile} can be any |
| 77 | object with a \function{write} method. If \var{csvfile} is a file object, |
| 78 | it must be opened with the 'b' flag on platforms where that makes a |
| 79 | difference. An optional |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 80 | {}\var{dialect} parameter can be given which is used to define a set of |
| 81 | parameters specific to a particular CSV dialect. It may be an instance |
| 82 | of a subclass of the \class{Dialect} class or one of the strings |
| 83 | returned by the \function{list_dialects} function. The other optional |
| 84 | {}\var{fmtparam} keyword arguments can be given to override individual |
| 85 | formatting parameters in the current dialect. For more information |
| 86 | about the dialect and formatting parameters, see |
Raymond Hettinger | 6e380cd | 2003-09-10 18:54:49 +0000 | [diff] [blame] | 87 | section~\ref{csv-fmt-params}, ``Dialects and Formatting Parameters'' for |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 88 | details of these parameters. To make it as easy as possible to |
| 89 | interface with modules which implement the DB API, the value |
| 90 | \constant{None} is written as the empty string. While this isn't a |
| 91 | reversible transformation, it makes it easier to dump SQL NULL data values |
| 92 | to CSV files without preprocessing the data returned from a |
| 93 | \code{cursor.fetch*()} call. All other non-string data are stringified |
| 94 | with \function{str()} before being written. |
| 95 | \end{funcdesc} |
| 96 | |
| 97 | \begin{funcdesc}{register_dialect}{name, dialect} |
| 98 | Associate \var{dialect} with \var{name}. \var{dialect} must be a subclass |
| 99 | of \class{csv.Dialect}. \var{name} must be a string or Unicode object. |
| 100 | \end{funcdesc} |
| 101 | |
| 102 | \begin{funcdesc}{unregister_dialect}{name} |
| 103 | Delete the dialect associated with \var{name} from the dialect registry. An |
| 104 | \exception{Error} is raised if \var{name} is not a registered dialect |
| 105 | name. |
| 106 | \end{funcdesc} |
| 107 | |
| 108 | \begin{funcdesc}{get_dialect}{name} |
| 109 | Return the dialect associated with \var{name}. An \exception{Error} is |
| 110 | raised if \var{name} is not a registered dialect name. |
| 111 | \end{funcdesc} |
| 112 | |
| 113 | \begin{funcdesc}{list_dialects}{} |
| 114 | Return the names of all registered dialects. |
| 115 | \end{funcdesc} |
| 116 | |
| 117 | |
Skip Montanaro | 5d0136e | 2003-04-25 15:14:49 +0000 | [diff] [blame] | 118 | The \module{csv} module defines the following classes: |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 119 | |
Skip Montanaro | dffeed3 | 2003-10-03 14:03:01 +0000 | [diff] [blame] | 120 | \begin{classdesc}{DictReader}{csvfile\optional{, |
| 121 | fieldnames=\constant{None},\optional{, |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 122 | restkey=\constant{None}\optional{, |
| 123 | restval=\constant{None}\optional{, |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 124 | dialect=\code{'excel'}\optional{, |
Skip Montanaro | 10659f2 | 2004-04-16 03:21:01 +0000 | [diff] [blame] | 125 | *args, **kwds}}}}}} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 126 | Create an object which operates like a regular reader but maps the |
Skip Montanaro | dffeed3 | 2003-10-03 14:03:01 +0000 | [diff] [blame] | 127 | information read into a dict whose keys are given by the optional |
| 128 | {} \var{fieldnames} |
| 129 | parameter. If the \var{fieldnames} parameter is omitted, the values in |
| 130 | the first row of the \var{csvfile} will be used as the fieldnames. |
| 131 | If the row read has fewer fields than the fieldnames sequence, |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 132 | the value of \var{restval} will be used as the default value. If the row |
| 133 | read has more fields than the fieldnames sequence, the remaining data is |
| 134 | added as a sequence keyed by the value of \var{restkey}. If the row read |
| 135 | has fewer fields than the fieldnames sequence, the remaining keys take the |
Skip Montanaro | 10659f2 | 2004-04-16 03:21:01 +0000 | [diff] [blame] | 136 | value of the optional \var{restval} parameter. Any other optional or |
| 137 | keyword arguments are passed to the underlying \class{reader} instance. |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 138 | \end{classdesc} |
| 139 | |
| 140 | |
| 141 | \begin{classdesc}{DictWriter}{csvfile, fieldnames\optional{, |
| 142 | restval=""\optional{, |
| 143 | extrasaction=\code{'raise'}\optional{, |
Skip Montanaro | 10659f2 | 2004-04-16 03:21:01 +0000 | [diff] [blame] | 144 | dialect=\code{'excel'}\optional{, |
| 145 | *args, **kwds}}}}} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 146 | Create an object which operates like a regular writer but maps dictionaries |
| 147 | onto output rows. The \var{fieldnames} parameter identifies the order in |
| 148 | which values in the dictionary passed to the \method{writerow()} method are |
| 149 | written to the \var{csvfile}. The optional \var{restval} parameter |
| 150 | specifies the value to be written if the dictionary is missing a key in |
| 151 | \var{fieldnames}. If the dictionary passed to the \method{writerow()} |
| 152 | method contains a key not found in \var{fieldnames}, the optional |
| 153 | \var{extrasaction} parameter indicates what action to take. If it is set |
| 154 | to \code{'raise'} a \exception{ValueError} is raised. If it is set to |
Skip Montanaro | 10659f2 | 2004-04-16 03:21:01 +0000 | [diff] [blame] | 155 | \code{'ignore'}, extra values in the dictionary are ignored. Any other |
| 156 | optional or keyword arguments are passed to the underlying \class{writer} |
| 157 | instance. |
Skip Montanaro | dffeed3 | 2003-10-03 14:03:01 +0000 | [diff] [blame] | 158 | |
| 159 | Note that unlike the \class{DictReader} class, the \var{fieldnames} |
| 160 | parameter of the \class{DictWriter} is not optional. Since Python's |
| 161 | \class{dict} objects are not ordered, there is not enough information |
| 162 | available to deduce the order in which the row should be written to the |
| 163 | \var{csvfile}. |
| 164 | |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 165 | \end{classdesc} |
| 166 | |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 167 | \begin{classdesc*}{Dialect}{} |
| 168 | The \class{Dialect} class is a container class relied on primarily for its |
| 169 | attributes, which are used to define the parameters for a specific |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 170 | \class{reader} or \class{writer} instance. |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 171 | \end{classdesc*} |
| 172 | |
Skip Montanaro | 7789237 | 2003-05-19 15:33:36 +0000 | [diff] [blame] | 173 | \begin{classdesc}{Sniffer}{} |
| 174 | The \class{Sniffer} class is used to deduce the format of a CSV file. |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 175 | \end{classdesc} |
| 176 | |
| 177 | The \class{Sniffer} class provides a single method: |
| 178 | |
Skip Montanaro | 7789237 | 2003-05-19 15:33:36 +0000 | [diff] [blame] | 179 | \begin{methoddesc}{sniff}{sample\optional{,delimiters=None}} |
| 180 | Analyze the given \var{sample} and return a \class{Dialect} subclass |
| 181 | reflecting the parameters found. If the optional \var{delimiters} parameter |
| 182 | is given, it is interpreted as a string containing possible valid delimiter |
| 183 | characters. |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 184 | \end{methoddesc} |
| 185 | |
| 186 | \begin{methoddesc}{has_header}{sample} |
| 187 | Analyze the sample text (presumed to be in CSV format) and return |
| 188 | \constant{True} if the first row appears to be a series of column |
| 189 | headers. |
| 190 | \end{methoddesc} |
| 191 | |
| 192 | |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 193 | The \module{csv} module defines the following constants: |
| 194 | |
Skip Montanaro | a104556 | 2003-06-04 15:30:13 +0000 | [diff] [blame] | 195 | \begin{datadesc}{QUOTE_ALL} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 196 | Instructs \class{writer} objects to quote all fields. |
| 197 | \end{datadesc} |
| 198 | |
| 199 | \begin{datadesc}{QUOTE_MINIMAL} |
| 200 | Instructs \class{writer} objects to only quote those fields which contain |
| 201 | the current \var{delimiter} or begin with the current \var{quotechar}. |
| 202 | \end{datadesc} |
| 203 | |
| 204 | \begin{datadesc}{QUOTE_NONNUMERIC} |
| 205 | Instructs \class{writer} objects to quote all non-numeric fields. |
| 206 | \end{datadesc} |
| 207 | |
| 208 | \begin{datadesc}{QUOTE_NONE} |
| 209 | Instructs \class{writer} objects to never quote fields. When the current |
| 210 | \var{delimiter} occurs in output data it is preceded by the current |
| 211 | \var{escapechar} character. When \constant{QUOTE_NONE} is in effect, it |
| 212 | is an error not to have a single-character \var{escapechar} defined, even if |
| 213 | no data to be written contains the \var{delimiter} character. |
| 214 | \end{datadesc} |
| 215 | |
| 216 | |
| 217 | The \module{csv} module defines the following exception: |
| 218 | |
| 219 | \begin{excdesc}{Error} |
| 220 | Raised by any of the functions when an error is detected. |
| 221 | \end{excdesc} |
| 222 | |
| 223 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 224 | \subsection{Dialects and Formatting Parameters\label{csv-fmt-params}} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 225 | |
| 226 | To make it easier to specify the format of input and output records, |
| 227 | specific formatting parameters are grouped together into dialects. A |
| 228 | dialect is a subclass of the \class{Dialect} class having a set of specific |
| 229 | methods and a single \method{validate()} method. When creating \class{reader} |
| 230 | or \class{writer} objects, the programmer can specify a string or a subclass |
| 231 | of the \class{Dialect} class as the dialect parameter. In addition to, or |
| 232 | instead of, the \var{dialect} parameter, the programmer can also specify |
| 233 | individual formatting parameters, which have the same names as the |
Raymond Hettinger | 6f6d7b93 | 2003-08-31 05:44:54 +0000 | [diff] [blame] | 234 | attributes defined below for the \class{Dialect} class. |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 235 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 236 | Dialects support the following attributes: |
| 237 | |
| 238 | \begin{memberdesc}[Dialect]{delimiter} |
| 239 | A one-character string used to separate fields. It defaults to \code{','}. |
| 240 | \end{memberdesc} |
| 241 | |
| 242 | \begin{memberdesc}[Dialect]{doublequote} |
| 243 | Controls how instances of \var{quotechar} appearing inside a field should be |
Skip Montanaro | 7895146 | 2004-01-21 13:34:35 +0000 | [diff] [blame] | 244 | themselves be quoted. When \constant{True}, the character is doubled. |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 245 | When \constant{False}, the \var{escapechar} must be a one-character string |
| 246 | which is used as a prefix to the \var{quotechar}. It defaults to |
| 247 | \constant{True}. |
| 248 | \end{memberdesc} |
| 249 | |
| 250 | \begin{memberdesc}[Dialect]{escapechar} |
| 251 | A one-character string used to escape the \var{delimiter} if \var{quoting} |
| 252 | is set to \constant{QUOTE_NONE}. It defaults to \constant{None}. |
| 253 | \end{memberdesc} |
| 254 | |
| 255 | \begin{memberdesc}[Dialect]{lineterminator} |
| 256 | The string used to terminate lines in the CSV file. It defaults to |
| 257 | \code{'\e r\e n'}. |
| 258 | \end{memberdesc} |
| 259 | |
| 260 | \begin{memberdesc}[Dialect]{quotechar} |
| 261 | A one-character string used to quote elements containing the \var{delimiter} |
| 262 | or which start with the \var{quotechar}. It defaults to \code{'"'}. |
| 263 | \end{memberdesc} |
| 264 | |
| 265 | \begin{memberdesc}[Dialect]{quoting} |
| 266 | Controls when quotes should be generated by the writer. It can take on any |
Raymond Hettinger | 6f6d7b93 | 2003-08-31 05:44:54 +0000 | [diff] [blame] | 267 | of the \constant{QUOTE_*} constants (see section~\ref{csv-contents}) |
| 268 | and defaults to \constant{QUOTE_MINIMAL}. |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 269 | \end{memberdesc} |
| 270 | |
| 271 | \begin{memberdesc}[Dialect]{skipinitialspace} |
| 272 | When \constant{True}, whitespace immediately following the \var{delimiter} |
| 273 | is ignored. The default is \constant{False}. |
| 274 | \end{memberdesc} |
| 275 | |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 276 | |
| 277 | \subsection{Reader Objects} |
| 278 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 279 | Reader objects (\class{DictReader} instances and objects returned by |
Raymond Hettinger | 6f6d7b93 | 2003-08-31 05:44:54 +0000 | [diff] [blame] | 280 | the \function{reader()} function) have the following public methods: |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 281 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 282 | \begin{methoddesc}[csv reader]{next}{} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 283 | Return the next row of the reader's iterable object as a list, parsed |
| 284 | according to the current dialect. |
| 285 | \end{methoddesc} |
| 286 | |
| 287 | |
| 288 | \subsection{Writer Objects} |
| 289 | |
Skip Montanaro | ba0485a | 2004-01-21 13:47:04 +0000 | [diff] [blame] | 290 | \class{Writer} objects (\class{DictWriter} instances and objects returned by |
| 291 | the \function{writer()} function) have the following public methods. A |
| 292 | {}\var{row} must be a sequence of strings or numbers for \class{Writer} |
| 293 | objects and a dictionary mapping fieldnames to strings or numbers (by |
| 294 | passing them through \function{str()} first) for {}\class{DictWriter} |
| 295 | objects. Note that complex numbers are written out surrounded by parens. |
| 296 | This may cause some problems for other programs which read CSV files |
| 297 | (assuming they support complex numbers at all). |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 298 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 299 | \begin{methoddesc}[csv writer]{writerow}{row} |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 300 | Write the \var{row} parameter to the writer's file object, formatted |
| 301 | according to the current dialect. |
| 302 | \end{methoddesc} |
| 303 | |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 304 | \begin{methoddesc}[csv writer]{writerows}{rows} |
Skip Montanaro | ba0485a | 2004-01-21 13:47:04 +0000 | [diff] [blame] | 305 | Write all the \var{rows} parameters (a list of \var{row} objects as |
| 306 | described above) to the writer's file object, formatted |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 307 | according to the current dialect. |
| 308 | \end{methoddesc} |
| 309 | |
| 310 | |
| 311 | \subsection{Examples} |
| 312 | |
| 313 | The ``Hello, world'' of csv reading is |
| 314 | |
| 315 | \begin{verbatim} |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 316 | import csv |
Skip Montanaro | bdda9f3 | 2004-03-17 01:24:17 +0000 | [diff] [blame] | 317 | reader = csv.reader(file("some.csv", "rb")) |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 318 | for row in reader: |
| 319 | print row |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 320 | \end{verbatim} |
| 321 | |
| 322 | The corresponding simplest possible writing example is |
| 323 | |
| 324 | \begin{verbatim} |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 325 | import csv |
Skip Montanaro | bdda9f3 | 2004-03-17 01:24:17 +0000 | [diff] [blame] | 326 | writer = csv.writer(file("some.csv", "wb")) |
Fred Drake | 9635268 | 2003-04-25 18:02:34 +0000 | [diff] [blame] | 327 | for row in someiterable: |
| 328 | writer.writerow(row) |
Skip Montanaro | b4a0417 | 2003-03-20 23:29:12 +0000 | [diff] [blame] | 329 | \end{verbatim} |