[New-bugs-announce] [issue23171] csv.writer.writerow() does not accept generator (must be coerced to list)

Jon Dufresne report at bugs.python.org
Mon Jan 5 18:31:42 CET 2015


New submission from Jon Dufresne:

The csv.writer.writerow() does not accept a generator as input. I find this counter-intuitive and against the spirit of similar APIs. If the generator is coerced to a list, everything works as expected. See the following test script which fails on the line "w.writerow(g)". In my opinion, this line should work identically to the line "w.writerow(list(g))".

---
import csv

f = open('foo.csv', 'w')
w = csv.writer(f)
g = (i for i in ['a', 'b', 'c'])
w.writerow(list(g))
g = (i for i in ['a', 'b', 'c'])
w.writerow(g)
---

----------
components: Library (Lib)
messages: 233470
nosy: jdufresne
priority: normal
severity: normal
status: open
title: csv.writer.writerow() does not accept generator (must be coerced to list)
type: behavior
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23171>
_______________________________________


More information about the New-bugs-announce mailing list