summaryrefslogtreecommitdiffstats
path: root/Lib/csv.py
diff options
context:
space:
mode:
authorSkip Montanaro <skip.montanaro@gmail.com>2024-01-18 22:18:42 (GMT)
committerGitHub <noreply@github.com>2024-01-18 22:18:42 (GMT)
commit72abb8c5d487ead9eb115fec8132ccef5ba189e5 (patch)
treecb8111dc4a58e39d0d6a1deca86d858b823b40aa /Lib/csv.py
parent68a7b78cd5185cbd9456f42c15ecf872a7c16f44 (diff)
downloadcpython-72abb8c5d487ead9eb115fec8132ccef5ba189e5.zip
cpython-72abb8c5d487ead9eb115fec8132ccef5ba189e5.tar.gz
cpython-72abb8c5d487ead9eb115fec8132ccef5ba189e5.tar.bz2
gh-114123: Migrate docstring from _csv to csv (#114124)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: Éric <merwok@netwok.org>
Diffstat (limited to 'Lib/csv.py')
-rw-r--r--Lib/csv.py76
1 files changed, 69 insertions, 7 deletions
diff --git a/Lib/csv.py b/Lib/csv.py
index 77f30c8..a079279 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -1,28 +1,90 @@
-"""
-csv.py - read/write/investigate CSV files
+r"""
+CSV parsing and writing.
+
+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_STRINGS means that quotes are always placed around
+ fields which are strings. Note that the Python value None
+ is not a string.
+ csv.QUOTE_NOTNULL means that quotes are only placed around fields
+ that are not the Python value None.
+ 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
"""
import re
import types
-from _csv import Error, __version__, writer, reader, register_dialect, \
+from _csv import Error, writer, reader, register_dialect, \
unregister_dialect, get_dialect, list_dialects, \
field_size_limit, \
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
- QUOTE_STRINGS, QUOTE_NOTNULL, \
- __doc__
+ QUOTE_STRINGS, QUOTE_NOTNULL
from _csv import Dialect as _Dialect
from io import StringIO
__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
"QUOTE_STRINGS", "QUOTE_NOTNULL",
- "Error", "Dialect", "__doc__", "excel", "excel_tab",
+ "Error", "Dialect", "excel", "excel_tab",
"field_size_limit", "reader", "writer",
"register_dialect", "get_dialect", "list_dialects", "Sniffer",
- "unregister_dialect", "__version__", "DictReader", "DictWriter",
+ "unregister_dialect", "DictReader", "DictWriter",
"unix_dialect"]
+__version__ = "1.0"
+
+
class Dialect:
"""Describe a CSV dialect.