Skip to content

Commit bf62019

Browse files
lul-casStanFromIreland
authored andcommitted
gh-151556: Show example CSV file content in the csv module docs (GH-151563)
(cherry picked from commit 7915c4a) Co-authored-by: Lucas <lucasefernandes333@gmail.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent fe5dc86 commit bf62019

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Doc/library/csv.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ The :mod:`!csv` module defines the following functions:
8181
Spam, Spam, Spam, Spam, Spam, Baked Beans
8282
Spam, Lovely Spam, Wonderful Spam
8383

84+
where :file:`eggs.csv` contains:
85+
86+
.. code-block:: text
87+
88+
Spam Spam Spam Spam Spam |Baked Beans|
89+
Spam |Lovely Spam| |Wonderful Spam|
90+
8491
8592
.. function:: writer(csvfile, /, dialect='excel', **fmtparams)
8693

@@ -110,6 +117,13 @@ The :mod:`!csv` module defines the following functions:
110117
spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
111118
spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
112119

120+
which writes :file:`eggs.csv` containing:
121+
122+
.. code-block:: text
123+
124+
Spam Spam Spam Spam Spam |Baked Beans|
125+
Spam |Lovely Spam| |Wonderful Spam|
126+
113127
114128
.. function:: register_dialect(name, /, dialect='excel', **fmtparams)
115129

@@ -191,6 +205,14 @@ The :mod:`!csv` module defines the following classes:
191205
>>> print(row)
192206
{'first_name': 'John', 'last_name': 'Cleese'}
193207

208+
where :file:`names.csv` contains:
209+
210+
.. code-block:: text
211+
212+
first_name,last_name
213+
Eric,Idle
214+
John,Cleese
215+
194216
195217
.. class:: DictWriter(f, fieldnames, restval='', extrasaction='raise', \
196218
dialect='excel', *args, **kwds)
@@ -228,6 +250,15 @@ The :mod:`!csv` module defines the following classes:
228250
writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
229251
writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
230252

253+
which writes :file:`names.csv` containing:
254+
255+
.. code-block:: text
256+
257+
first_name,last_name
258+
Baked,Beans
259+
Lovely,Spam
260+
Wonderful,Spam
261+
231262
232263
.. class:: Dialect
233264

0 commit comments

Comments
 (0)