[issue23495] The writer.writerows method should be documented as accepting any iterable (not only a list)

New submission from Steven Barker: 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-itera... 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). ---------- assignee: docs@python components: Documentation messages: 236328 nosy: Steven.Barker, docs@python priority: normal severity: normal status: open title: The writer.writerows method should be documented as accepting any iterable (not only a list) type: enhancement versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

Steven Barker added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

Changes by SilentGhost <ghost.adh@gmail.com>: ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

R. David Murray added the comment: 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. ---------- stage: -> needs patch versions: -Python 3.2, Python 3.3, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

Changes by Peter Otten <__peter__@web.de>: ---------- nosy: +peter.otten _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

Martijn Pieters added the comment: 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). ---------- nosy: +mjpieters _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue23495> _______________________________________

Change by Zackery Spytz <zspytz@gmail.com>: ---------- keywords: +patch pull_requests: +6032 stage: needs patch -> patch review _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Zackery Spytz <zspytz@gmail.com> added the comment: Commit 7901b48a1f89b9bfa9d111ae3725400b466a9baa removed the unnecessary list conversion (3.5+), but the documentation issue remains. ---------- nosy: +ZackerySpytz versions: +Python 3.6, Python 3.7, Python 3.8 -Python 3.4, Python 3.5 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Change by Nathaniel Manista <nathaniel@google.com>: ---------- nosy: +Nathaniel Manista _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Mariatta Wijaya <mariatta.wijaya@gmail.com> added the comment: 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/a801cf164be7c62b6a6dba47ff91d6c3edb... ---------- nosy: +Mariatta _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +6969 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +6970 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +6971 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: 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/db3039085845af5d68ab863f03e9684681b... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: 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/949da9e44b4e0d5b32745b91f9582158442... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: 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/af3685963652721269ca0196f9f7fc08d3e... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________

Mariatta Wijaya <mariatta.wijaya@gmail.com> added the comment: Thanks all! ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue23495> _______________________________________
participants (9)
-
Mariatta Wijaya
-
Martijn Pieters
-
miss-islington
-
Nathaniel Manista
-
Peter Otten
-
R. David Murray
-
SilentGhost
-
Steven Barker
-
Zackery Spytz