[issue5445] codecs.StreamWriter.writelines problem when passed generator

Daniel Lescohier report at bugs.python.org
Tue Mar 10 16:36:41 CET 2009


Daniel Lescohier <daniel.lescohier at cbs.com> added the comment:

Let me give an example of why it's important that writelines 
iteratively writes.  For:

rows = (line[:-1].split('\t') for line in in_file)
projected = (keep_fields(row, 0, 3, 7) for row in rows)
filtered = (row for row in projected if row[2]=='1')
out_file.writelines('\t'.join(row)+'\n' for row in filtered)

For a large input file, for a regular out_file object, this will work. 
For a codecs.StreamWriter wrapped out_file object, this won't work, 
because it's not following the file protocol that writelines should 
iteratively write.

----------
message_count: 4.0 -> 5.0

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


More information about the Python-bugs-list mailing list