This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: The writer.writerows method should be documented as accepting any iterable (not only a list)
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Mariatta, Nathaniel Manista, Steven.Barker, ZackerySpytz, docs@python, miss-islington, mjpieters, peter.otten, r.david.murray
Priority: normal Keywords: patch

Created on 2015-02-20 20:45 by Steven.Barker, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6316 merged ZackerySpytz, 2018-03-31 02:13
PR 7341 merged miss-islington, 2018-06-02 15:03
PR 7342 merged miss-islington, 2018-06-02 15:04
PR 7343 merged miss-islington, 2018-06-02 15:05
Messages (10)
msg236328 - (view) Author: Steven Barker (Steven.Barker) * Date: 2015-02-20 20:45
The documentation for the csv.writer.writerows method says that it expects "a list of row objects", when it really will accept any iterable that yields rows (such as a generator). While it's often nice for code to be more accepting than the documented requirements, I think the docs in this case should state that writerows() expects an iterable, rather than misinforming users that a list is required.

This documentation issue was brought up in a Stack Overflow question here:

I expect the necessary documentation patch will be pretty trivial, and if nobody else gets to it first, I will try to provide one when I have enough time to update my cpython checkout (not soon, alas).
msg236346 - (view) Author: Steven Barker (Steven.Barker) * Date: 2015-02-21 01:03
Another Stack Overflow user pointed out that the DictWriter's writerows implementation (in pure Python) unnecessarily converts whatever its argument is into a list in memory before passing it on to the builtin writer.writerows method which would accept any iterable type. Probably it should be changed to use map or a generator expression instead.

So, perhaps this issue isn't purely documentation, but actually a small behavior enhancement as well.
msg236361 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-02-21 14:13
Seems reasonable to me.  Do you want to prepare patches?  The doc patch should be separate, since it applies to all active versions, but the code change to dictwriter would go only into 3.5.
msg242285 - (view) Author: Martijn Pieters (mjpieters) * Date: 2015-04-30 19:52
I'd be happy to provide a patch for the DictWriter.writerows code; I was naively counting on it accepting an iterable and that it would not pull the whole sequence into memory (while feeding it gigabytes of CSV data).
msg314730 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2018-03-31 02:26
Commit 7901b48a1f89b9bfa9d111ae3725400b466a9baa removed the unnecessary list conversion (3.5+), but the documentation issue remains.
msg318499 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-06-02 15:02
New changeset a801cf164be7c62b6a6dba47ff91d6c3edb67729 by Mariatta (Zackery Spytz) in branch 'master':
bpo-23495: Correct the documentation for writerows() of csv Writer objects (GH-6316)
msg318501 - (view) Author: miss-islington (miss-islington) Date: 2018-06-02 15:37
New changeset db3039085845af5d68ab863f03e9684681b1516d by Miss Islington (bot) in branch '3.6':
bpo-23495: Correct the documentation for writerows() of csv Writer objects (GH-6316)
msg318502 - (view) Author: miss-islington (miss-islington) Date: 2018-06-02 15:40
New changeset 949da9e44b4e0d5b32745b91f9582158442b68d1 by Miss Islington (bot) in branch '3.7':
bpo-23495: Correct the documentation for writerows() of csv Writer objects (GH-6316)
msg318503 - (view) Author: miss-islington (miss-islington) Date: 2018-06-02 15:41
New changeset af3685963652721269ca0196f9f7fc08d3e830b7 by Miss Islington (bot) in branch '2.7':
bpo-23495: Correct the documentation for writerows() of csv Writer objects (GH-6316)
msg318504 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-06-02 15:54
Thanks all!
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67683
2018-06-02 15:54:24Mariattasetstatus: open -> closed
resolution: fixed
messages: + msg318504

stage: patch review -> resolved
2018-06-02 15:41:29miss-islingtonsetmessages: + msg318503
2018-06-02 15:40:03miss-islingtonsetmessages: + msg318502
2018-06-02 15:37:30miss-islingtonsetnosy: + miss-islington
messages: + msg318501
2018-06-02 15:05:53miss-islingtonsetpull_requests: + pull_request6971
2018-06-02 15:04:59miss-islingtonsetpull_requests: + pull_request6970
2018-06-02 15:03:54miss-islingtonsetpull_requests: + pull_request6969
2018-06-02 15:02:18Mariattasetnosy: + Mariatta
messages: + msg318499
2018-05-26 18:44:35Nathaniel Manistasetnosy: + Nathaniel Manista
2018-03-31 02:26:04ZackerySpytzsetnosy: + ZackerySpytz

messages: + msg314730
versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.4, Python 3.5
2018-03-31 02:13:41ZackerySpytzsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request6032
2015-04-30 19:52:59mjpieterssetnosy: + mjpieters
messages: + msg242285
2015-03-07 11:57:16peter.ottensetnosy: + peter.otten
2015-02-21 14:13:47r.david.murraysetstage: needs patch
messages: + msg236361
versions: - Python 3.2, Python 3.3, Python 3.6
2015-02-21 10:44:07SilentGhostsetnosy: + r.david.murray
2015-02-21 01:03:08Steven.Barkersetmessages: + msg236346
2015-02-20 20:45:53Steven.Barkercreate