• Home
  • Raw
  • Download

Lines Matching full:csv

2 :mod:`csv` --- CSV File Reading and Writing
5 .. module:: csv
13 single: csv
16 The so-called CSV (Comma Separated Values) format is the most common import and
17 export format for spreadsheets and databases. There is no "CSV standard", so
21 make it annoying to process CSV files from multiple sources. Still, while the
27 The :mod:`csv` module implements classes to read and write tabular data in CSV
30 knowing the precise details of the CSV format used by Excel. Programmers can
31 also describe the CSV formats understood by other applications or define their
32 own special-purpose CSV formats.
34 The :mod:`csv` module's :class:`reader` and :class:`writer` objects read and
40 This version of the :mod:`csv` module doesn't support Unicode input. Also,
43 section :ref:`csv-examples`.
48 :pep:`305` - CSV File API
57 The :mod:`csv` module defines the following functions:
68 specific to a particular CSV dialect. It may be an instance of a subclass of
73 section :ref:`csv-fmt-params`.
75 Each row read from the csv file is returned as a list of strings. No
80 >>> import csv
81 >>> with open('eggs.csv', 'rb') as csvfile:
82 ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
105 particular CSV dialect. It may be an instance of a subclass of the
110 section :ref:`csv-fmt-params`. To make it
114 CSV files without preprocessing the data returned from a ``cursor.fetch*`` call.
120 import csv
121 with open('eggs.csv', 'wb') as csvfile:
122 spamwriter = csv.writer(csvfile, delimiter=' ',
123 quotechar='|', quoting=csv.QUOTE_MINIMAL)
134 parameters, see section :ref:`csv-fmt-params`.
165 The :mod:`csv` module defines the following classes:
186 >>> import csv
187 >>> with open('names.csv') as csvfile:
188 ... reader = csv.DictReader(csvfile)
220 import csv
222 with open('names.csv', 'w') as csvfile:
224 writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
241 The :class:`excel` class defines the usual properties of an Excel-generated CSV
253 The :class:`Sniffer` class is used to deduce the format of a CSV file.
267 Analyze the sample text (presumed to be in CSV format) and return
272 with open('example.csv', 'rb') as csvfile:
273 dialect = csv.Sniffer().sniff(csvfile.read(1024))
275 reader = csv.reader(csvfile, dialect)
276 # ... process CSV file contents here ...
279 The :mod:`csv` module defines the following constants:
309 The :mod:`csv` module defines the following exception:
382 :ref:`csv-contents`) and defaults to :const:`QUOTE_MINIMAL`.
393 When ``True``, raise exception :exc:`Error` on bad CSV input.
445 read CSV files (assuming they support complex numbers at all).
483 The simplest example of reading a CSV file::
485 import csv
486 with open('some.csv', 'rb') as f:
487 reader = csv.reader(f)
493 import csv
495 reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
501 import csv
502 with open('some.csv', 'wb') as f:
503 writer = csv.writer(f)
508 import csv
509 csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
511 reader = csv.reader(f, 'unixpwd')
515 import csv, sys
516 filename = 'some.csv'
518 reader = csv.reader(f)
522 except csv.Error as e:
528 import csv
529 for row in csv.reader(['one,two,three']):
532 The :mod:`csv` module doesn't directly support reading and writing Unicode, but
537 :func:`unicode_csv_reader` below is a :term:`generator` that wraps :class:`csv.reader`
538 to handle Unicode CSV data (a list of Unicode strings). :func:`utf_8_encoder`
540 a time. The encoded strings are parsed by the CSV reader, and
543 import csv
545 def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
546 # csv.py doesn't do Unicode; encode temporarily as UTF-8:
547 csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
562 import csv, codecs, cStringIO
579 A CSV reader which will iterate over lines in the CSV file "f",
583 def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
585 self.reader = csv.reader(f, dialect=dialect, **kwds)
596 A CSV writer which will write rows to CSV file "f",
600 def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
603 self.writer = csv.writer(self.queue, dialect=dialect, **kwds)