Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-132813: Fix the csv documentation for quoting and escaping#133209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
serhiy-storchaka wants to merge2 commits intopython:mainChoose a base branch fromserhiy-storchaka:docs-csv-quoting
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+26 −12
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
38 changes: 26 additions & 12 deletionsDoc/library/csv.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -323,8 +323,8 @@ The :mod:`csv` module defines the following constants: | ||
.. data:: QUOTE_MINIMAL | ||
Instructs :class:`writer` objects to only quote those fields which contain | ||
special characters such as *delimiter*, *quotechar*, ``'\r'``, ``'\n'`` | ||
or any of the characters in*lineterminator*. | ||
.. data:: QUOTE_NONNUMERIC | ||
@@ -336,10 +336,13 @@ The :mod:`csv` module defines the following constants: | ||
.. data:: QUOTE_NONE | ||
Instructs :class:`writer` objects to never quote fields. | ||
When the current *delimiter*, *quotechar*, *escapechar*, ``'\r'``, ``'\n'`` | ||
or any of the characters in *lineterminator* occurs in output data | ||
it is preceded by the current *escapechar* character. | ||
If *escapechar* is not set, the writer will raise :exc:`Error` if | ||
any characters that require escaping are encountered. | ||
Set *quotechar* to ``None`` to prevent its escaping. | ||
Instructs :class:`reader` objects to perform no special processing of quote characters. | ||
@@ -408,9 +411,16 @@ Dialects support the following attributes: | ||
.. attribute:: Dialect.escapechar | ||
A one-character string used by the writer to escape characters that | ||
require escaping: | ||
* the *delimiter*, the *quotechar*, ``'\r'``, ``'\n'`` and any of the | ||
characters in *lineterminator* are escaped if *quoting* is set to | ||
:const:`QUOTE_NONE`; | ||
* the *quotechar* is escaped if *doublequote* is :const:`False`; | ||
* the *escapechar* itself. | ||
On reading, the *escapechar* removes any special meaning from | ||
the following character. It defaults to :const:`None`, which disables escaping. | ||
.. versionchanged:: 3.11 | ||
@@ -430,9 +440,12 @@ Dialects support the following attributes: | ||
.. attribute:: Dialect.quotechar | ||
A one-character string used to quote fields containing special characters, | ||
such as the *delimiter* or the *quotechar*, or which contain new-line | ||
characters (``'\r'``, ``'\n'`` or any of the characters in *lineterminator*). | ||
It defaults to ``'"'``. | ||
Can be set to ``None`` to prevent escaping ``'"'`` if *quoting* is set | ||
serhiy-storchaka marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
to :const:`QUOTE_NONE`. | ||
.. versionchanged:: 3.11 | ||
An empty *quotechar* is not allowed. | ||
@@ -441,7 +454,8 @@ Dialects support the following attributes: | ||
Controls when quotes should be generated by the writer and recognised by the | ||
reader. It can take on any of the :ref:`QUOTE_\* constants <csv-constants>` | ||
and defaults to :const:`QUOTE_MINIMAL` if *quotechar* is not ``None``, | ||
and :const:`QUOTE_NONE` otherwise. | ||
.. attribute:: Dialect.skipinitialspace | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.