Issue 23495: The writer.writerows method should be documented as accepting any iterable (not only a list) (original) (raw)

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: http://stackoverflow.com/questions/28636848/csv-writer-writerows-takes-iterator 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) https://github.com/python/cpython/commit/a801cf164be7c62b6a6dba47ff91d6c3edb67729
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) https://github.com/python/cpython/commit/db3039085845af5d68ab863f03e9684681b1516d
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) https://github.com/python/cpython/commit/949da9e44b4e0d5b32745b91f9582158442b68d1
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) https://github.com/python/cpython/commit/af3685963652721269ca0196f9f7fc08d3e830b7
msg318504 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2018-06-02 15:54
Thanks all!
History
Date User Action Args
2022-04-11 14:58:13 admin set github: 67683
2018-06-02 15:54:24 Mariatta set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2018-06-02 15:41:29 miss-islington set messages: +
2018-06-02 15:40:03 miss-islington set messages: +
2018-06-02 15:37:30 miss-islington set nosy: + miss-islingtonmessages: +
2018-06-02 15:05:53 miss-islington set pull_requests: + <pull%5Frequest6971>
2018-06-02 15:04:59 miss-islington set pull_requests: + <pull%5Frequest6970>
2018-06-02 15:03:54 miss-islington set pull_requests: + <pull%5Frequest6969>
2018-06-02 15:02:18 Mariatta set nosy: + Mariattamessages: +
2018-05-26 18:44:35 Nathaniel Manista set nosy: + Nathaniel Manista
2018-03-31 02:26:04 ZackerySpytz set nosy: + ZackerySpytzmessages: + versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.4, Python 3.5
2018-03-31 02:13:41 ZackerySpytz set keywords: + patchstage: needs patch -> patch reviewpull_requests: + <pull%5Frequest6032>
2015-04-30 19:52:59 mjpieters set nosy: + mjpietersmessages: +
2015-03-07 11:57:16 peter.otten set nosy: + peter.otten
2015-02-21 14:13:47 r.david.murray set stage: needs patchmessages: + versions: - Python 3.2, Python 3.3, Python 3.6
2015-02-21 10:44:07 SilentGhost set nosy: + r.david.murray
2015-02-21 01:03:08 Steven.Barker set messages: +
2015-02-20 20:45:53 Steven.Barker create