Skip to content

Commit 82e023f

Browse files
miss-islingtonlul-casStanFromIreland
authored
[3.13] gh-151556: Show example CSV file content in the csv module docs (GH-151563) (#151986)
(cherry picked from commit 7915c4a) Co-authored-by: Lucas <lucasefernandes333@gmail.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent da45740 commit 82e023f

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
@@ -83,6 +83,13 @@ The :mod:`csv` module defines the following functions:
8383
Spam, Spam, Spam, Spam, Spam, Baked Beans
8484
Spam, Lovely Spam, Wonderful Spam
8585

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

@@ -112,6 +119,13 @@ The :mod:`csv` module defines the following functions:
112119
spamwriter.writerow(['Spam'] * 5 + ['Baked Beans'])
113120
spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
114121

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

@@ -193,6 +207,14 @@ The :mod:`csv` module defines the following classes:
193207
>>> print(row)
194208
{'first_name': 'John', 'last_name': 'Cleese'}
195209

210+
where :file:`names.csv` contains:
211+
212+
.. code-block:: text
213+
214+
first_name,last_name
215+
Eric,Idle
216+
John,Cleese
217+
196218
197219
.. class:: DictWriter(f, fieldnames, restval='', extrasaction='raise', \
198220
dialect='excel', *args, **kwds)
@@ -230,6 +252,15 @@ The :mod:`csv` module defines the following classes:
230252
writer.writerow({'first_name': 'Lovely', 'last_name': 'Spam'})
231253
writer.writerow({'first_name': 'Wonderful', 'last_name': 'Spam'})
232254

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

0 commit comments

Comments
 (0)