]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#1686390: add example for csv.Sniffer use.
authorGeorg Brandl <georg@python.org>
Sun, 6 Jan 2008 16:04:56 +0000 (16:04 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 6 Jan 2008 16:04:56 +0000 (16:04 +0000)
Doc/library/csv.rst

index 1d6308080ccd3abc807b32b5ea37922e24364ca6..89c9bf101441de2c37c214dbfa471d18c10899c4 100644 (file)
@@ -220,7 +220,6 @@ The :mod:`csv` module defines the following classes:
 
 The :class:`Sniffer` class provides two methods:
 
-
 .. method:: Sniffer.sniff(sample[, delimiters=None])
 
    Analyze the given *sample* and return a :class:`Dialect` subclass reflecting the
@@ -233,9 +232,17 @@ The :class:`Sniffer` class provides two methods:
    Analyze the sample text (presumed to be in CSV format) and return :const:`True`
    if the first row appears to be a series of column headers.
 
-The :mod:`csv` module defines the following constants:
+An example for :class:`Sniffer` use::
+
+   csvfile = open("example.csv")
+   dialect = csv.Sniffer().sniff(csvfile.read(1024))
+   csvfile.seek(0)
+   reader = csv.reader(csvfile, dialect)
+   # ... process CSV file contents here ...
 
 
+The :mod:`csv` module defines the following constants:
+
 .. data:: QUOTE_ALL
 
    Instructs :class:`writer` objects to quote all fields.