[Python-Dev] cpython: Closes issue 17467. Add readline and readlines support to

Antoine Pitrou solipsis at pitrou.net
Wed Mar 20 08:09:29 CET 2013


On Tue, 19 Mar 2013 21:44:15 -0700
Michael Foord <fuzzyman at voidspace.org.uk> wrote:
> 
> mock_open makes it easy to put a StringIO in place if that's what you want. It's just a simple helper function for providing some known data *along with the Mock api* to make asserts that it was used correctly. It isn't presenting a full file-system. My suggestion to the implementor of the patch was that read / readline / readlines be disconnected - but the patch provided allows them to be interleaved and I saw no reason to undo that.
> 
> If users want more complex behaviour (like universal newline support) they can use mock_open along with a StringIO.

This is not about complex behaviour but simply correct behaviour.
For the record, universal newlines are enabled by default in Python 3:

>>> with open("foo", "wb") as f: f.write(b"a\r\nb\rc\n")
... 
7
>>> with open("foo", "r") as f: print(list(f))
... 
['a\n', 'b\n', 'c\n']


Regards

Antoine.


More information about the Python-Dev mailing list