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) *  |
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) *  |
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) *  |
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) *  |
Date: 2018-06-02 15:54 |
Thanks all! |
|
|