[docs] [issue20501] fileinput module will read whole file into memory when using fileinput.hook_encoded

Zachary Ware report at bugs.python.org
Thu Feb 27 15:42:52 CET 2014


Zachary Ware added the comment:

Agreed with Vajrasky, the 2.7 commit wasn't as clean as it could be (sorry I didn't get an actual review done before you committed, I posted my last test results in a bit of a hurry).  The commented out line should either be removed, or used instead of the 'with' block above it.  I would actually vote for using writeTmp, and make a new issue for making writeTmp use a context manager.

Also, I think the new test_readline could be made a little clearer by putting

+        fi = FileInput(files=TESTFN, openhook=hook_encoded('ascii'), bufsize=8)
+        self.assertEqual(fi.readline(), u'A\n')
+        self.assertEqual(fi.readline(), u'B\r\n')
+        self.assertEqual(fi.readline(), u'C\r')

inside a `try ... except UnicodeDecodeError: self.fail('Read to end of file')` block.

----------

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


More information about the docs mailing list