csv - pydoc - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


csv
NAME MODULE REFERENCE DESCRIPTION CLASSES FUNCTIONS DATA VERSION FILE
Help on module csv:

NAME
    csv - CSV parsing and writing.

MODULE REFERENCE
    https://docs.python.org/3.10/library/csv.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    This module provides classes that assist in the reading and writing
    of Comma Separated Value (CSV) files, and implements the interface
    described by PEP 305.  Although many CSV files are simple to parse,
    the format is not formally defined by a stable specification and
    is subtle enough that parsing lines of a CSV file with something
    like line.split(",") is bound to fail.  The module supports three
    basic APIs: reading, writing, and registration of dialects.


    DIALECT REGISTRATION:

    Readers and writers support a dialect argument, which is a convenient
    handle on a group of settings.  When the dialect argument is a string,
    it identifies one of the dialects previously registered with the module.
    If it is a class or instance, the attributes of the argument are used as
    the settings for the reader or writer:

        class excel:
            delimiter = ','
            quotechar = '"'
            escapechar = None
            doublequote = True
            skipinitialspace = False
            lineterminator = '\r\n'
            quoting = QUOTE_MINIMAL

    SETTINGS:

        * quotechar - specifies a one-character string to use as the
            quoting character.  It defaults to '"'.
        * delimiter - specifies a one-character string to use as the
            field separator.  It defaults to ','.
        * skipinitialspace - specifies how to interpret spaces which
            immediately follow a delimiter.  It defaults to False, which
            means that spaces immediately following a delimiter is part
            of the following field.
        * lineterminator -  specifies the character sequence which should
            terminate rows.
        * quoting - controls when quotes should be generated by the writer.
            It can take on any of the following module constants:

            csv.QUOTE_MINIMAL means only when required, for example, when a
                field contains either the quotechar or the delimiter
            csv.QUOTE_ALL means that quotes are always placed around fields.
            csv.QUOTE_NONNUMERIC means that quotes are always placed around
                fields which do not parse as integers or floating point
                numbers.
            csv.QUOTE_NONE means that quotes are never placed around fields.
        * escapechar - specifies a one-character string used to escape
            the delimiter when quoting is set to QUOTE_NONE.
        * doublequote - controls the handling of quotes inside fields.  When
            True, two consecutive quotes are interpreted as one during read,
            and when writing, each quote character embedded in the data is
            written as two quotes

CLASSES
    builtins.Exception(builtins.BaseException)
        _csv.Error
    builtins.object
        Dialect
            excel
                excel_tab
            unix_dialect
        DictReader
        DictWriter
        Sniffer

    class Dialect(builtins.object)
     |  Describe a CSV dialect.
     |
     |  This must be subclassed (see csv.excel).  Valid attributes are:
     |  delimiter, quotechar, escapechar, doublequote, skipinitialspace,
     |  lineterminator, quoting.
     |
     |  Methods defined here:
     |
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |
     |  delimiter = None
     |
     |  doublequote = None
     |
     |  escapechar = None
     |
     |  lineterminator = None
     |
     |  quotechar = None
     |
     |  quoting = None
     |
     |  skipinitialspace = None

    class DictReader(builtins.object)
     |  DictReader(f, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)
     |
     |  Methods defined here:
     |
     |  __init__(self, f, fieldnames=None, restkey=None, restval=None, dialect='excel', *args, **kwds)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  __iter__(self)
     |
     |  __next__(self)
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  fieldnames

    class DictWriter(builtins.object)
     |  DictWriter(f, fieldnames, restval='', extrasaction='raise', dialect='excel', *args, **kwds)
     |
     |  Methods defined here:
     |
     |  __init__(self, f, fieldnames, restval='', extrasaction='raise', dialect='excel', *args, **kwds)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  writeheader(self)
     |
     |  writerow(self, rowdict)
     |
     |  writerows(self, rowdicts)
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)

    class Error(builtins.Exception)
     |  Method resolution order:
     |      Error
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |
     |  Methods inherited from builtins.Exception:
     |
     |  __init__(self, /, *args, **kwargs)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |
     |  __reduce__(...)
     |      Helper for pickle.
     |
     |  __repr__(self, /)
     |      Return repr(self).
     |
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |
     |  __setstate__(...)
     |
     |  __str__(self, /)
     |      Return str(self).
     |
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |
     |  __cause__
     |      exception cause
     |
     |  __context__
     |      exception context
     |
     |  __dict__
     |
     |  __suppress_context__
     |
     |  __traceback__
     |
     |  args

    class Sniffer(builtins.object)
     |  "Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
     |  Returns a Dialect object.
     |
     |  Methods defined here:
     |
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  has_header(self, sample)
     |
     |  sniff(self, sample, delimiters=None)
     |      Returns a dialect (or None) corresponding to the sample
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)

    class excel(Dialect)
     |  Describe the usual properties of Excel-generated CSV files.
     |
     |  Method resolution order:
     |      excel
     |      Dialect
     |      builtins.object
     |
     |  Data and other attributes defined here:
     |
     |  delimiter = ','
     |
     |  doublequote = True
     |
     |  lineterminator = '\r\n'
     |
     |  quotechar = '"'
     |
     |  quoting = 0
     |
     |  skipinitialspace = False
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from Dialect:
     |
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Dialect:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from Dialect:
     |
     |  escapechar = None

    class excel_tab(excel)
     |  Describe the usual properties of Excel-generated TAB-delimited files.
     |
     |  Method resolution order:
     |      excel_tab
     |      excel
     |      Dialect
     |      builtins.object
     |
     |  Data and other attributes defined here:
     |
     |  delimiter = '\t'
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from excel:
     |
     |  doublequote = True
     |
     |  lineterminator = '\r\n'
     |
     |  quotechar = '"'
     |
     |  quoting = 0
     |
     |  skipinitialspace = False
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from Dialect:
     |
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Dialect:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from Dialect:
     |
     |  escapechar = None

    class unix_dialect(Dialect)
     |  Describe the usual properties of Unix-generated CSV files.
     |
     |  Method resolution order:
     |      unix_dialect
     |      Dialect
     |      builtins.object
     |
     |  Data and other attributes defined here:
     |
     |  delimiter = ','
     |
     |  doublequote = True
     |
     |  lineterminator = '\n'
     |
     |  quotechar = '"'
     |
     |  quoting = 1
     |
     |  skipinitialspace = False
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from Dialect:
     |
     |  __init__(self)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from Dialect:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from Dialect:
     |
     |  escapechar = None

FUNCTIONS
    field_size_limit(...)
        Sets an upper limit on parsed fields.
            csv.field_size_limit([limit])

        Returns old limit. If limit is not given, no new limit is set and
        the old limit is returned

    get_dialect(...)
        Return the dialect instance associated with name.
        dialect = csv.get_dialect(name)

    list_dialects(...)
        Return a list of all know dialect names.
        names = csv.list_dialects()

    reader(...)
        csv_reader = reader(iterable [, dialect='excel']
                                [optional keyword args])
            for row in csv_reader:
                process(row)

        The "iterable" argument can be any object that returns a line
        of input for each iteration, such as a file object or a list.  The
        optional "dialect" parameter is discussed below.  The function
        also accepts optional keyword arguments which override settings
        provided by the dialect.

        The returned object is an iterator.  Each iteration returns a row
        of the CSV file (which can span multiple input lines).

    register_dialect(...)
        Create a mapping from a string name to a dialect class.
        dialect = csv.register_dialect(name[, dialect[, **fmtparams]])

    unregister_dialect(...)
        Delete the name/dialect mapping associated with a string name.
        csv.unregister_dialect(name)

    writer(...)
        csv_writer = csv.writer(fileobj [, dialect='excel']
                                    [optional keyword args])
            for row in sequence:
                csv_writer.writerow(row)

            [or]

            csv_writer = csv.writer(fileobj [, dialect='excel']
                                    [optional keyword args])
            csv_writer.writerows(rows)

        The "fileobj" argument can be any object that supports the file API.

DATA
    QUOTE_ALL = 1
    QUOTE_MINIMAL = 0
    QUOTE_NONE = 3
    QUOTE_NONNUMERIC = 2
    __all__ = ['QUOTE_MINIMAL', 'QUOTE_ALL', 'QUOTE_NONNUMERIC', 'QUOTE_NO...

VERSION
    1.0

FILE
    /usr/lib/python3.10/csv.py



Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:13 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!

^_back to top