• Home
  • Raw
  • Download

Lines Matching full:csv

1 :mod:`csv` --- CSV File Reading and Writing
4 .. module:: csv
9 **Source code:** :source:`Lib/csv.py`
12 single: csv
17 The so-called CSV (Comma Separated Values) format is the most common import and
18 export format for spreadsheets and databases. CSV format was used for many
22 differences can make it annoying to process CSV files from multiple sources.
28 The :mod:`csv` module implements classes to read and write tabular data in CSV
31 knowing the precise details of the CSV format used by Excel. Programmers can
32 also describe the CSV formats understood by other applications or define their
33 own special-purpose CSV formats.
35 The :mod:`csv` module's :class:`reader` and :class:`writer` objects read and
41 :pep:`305` - CSV File API
50 The :mod:`csv` module defines the following functions:
54 single: universal newlines; csv.reader function
64 specific to a particular CSV dialect. It may be an instance of a subclass of
69 section :ref:`csv-fmt-params`.
71 Each row read from the csv file is returned as a list of strings. No
77 >>> import csv
78 >>> with open('eggs.csv', newline='') as csvfile:
79 ... spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
93 particular CSV dialect. It may be an instance of a subclass of the
98 section :ref:`csv-fmt-params`. To make it
102 CSV files without preprocessing the data returned from a ``cursor.fetch*`` call.
107 import csv
108 with open('eggs.csv', 'w', newline='') as csvfile:
109 spamwriter = csv.writer(csvfile, delimiter=' ',
110 quotechar='|', quoting=csv.QUOTE_MINIMAL)
121 parameters, see section :ref:`csv-fmt-params`.
147 The :mod:`csv` module defines the following classes:
178 >>> import csv
179 >>> with open('names.csv', newline='') as csvfile:
180 ... reader = csv.DictReader(csvfile)
214 import csv
216 with open('names.csv', 'w', newline='') as csvfile:
218 writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
235 The :class:`excel` class defines the usual properties of an Excel-generated CSV
247 The :class:`unix_dialect` class defines the usual properties of a CSV file
256 The :class:`Sniffer` class is used to deduce the format of a CSV file.
270 Analyze the sample text (presumed to be in CSV format) and return
275 with open('example.csv', newline='') as csvfile:
276 dialect = csv.Sniffer().sniff(csvfile.read(1024))
278 reader = csv.reader(csvfile, dialect)
279 # ... process CSV file contents here ...
282 The :mod:`csv` module defines the following constants:
312 The :mod:`csv` module defines the following exception:
384 :ref:`csv-contents`) and defaults to :const:`QUOTE_MINIMAL`.
395 When ``True``, raise exception :exc:`Error` on bad CSV input.
444 read CSV files (assuming they support complex numbers at all).
490 The simplest example of reading a CSV file::
492 import csv
493 with open('some.csv', newline='') as f:
494 reader = csv.reader(f)
500 import csv
502 reader = csv.reader(f, delimiter=':', quoting=csv.QUOTE_NONE)
508 import csv
509 with open('some.csv', 'w', newline='') as f:
510 writer = csv.writer(f)
513 Since :func:`open` is used to open a CSV file for reading, the file
518 import csv
519 with open('some.csv', newline='', encoding='utf-8') as f:
520 reader = csv.reader(f)
529 import csv
530 csv.register_dialect('unixpwd', delimiter=':', quoting=csv.QUOTE_NONE)
532 reader = csv.reader(f, 'unixpwd')
536 import csv, sys
537 filename = 'some.csv'
539 reader = csv.reader(f)
543 except csv.Error as e:
549 import csv
550 for row in csv.reader(['one,two,three']):
559 ``newline=''``, since the csv module does its own