[New-bugs-announce] [issue5451] patch to make io.StringIO consistent with open with respect to newlines

Erick Tryzelaar report at bugs.python.org
Mon Mar 9 01:09:54 CET 2009


New submission from Erick Tryzelaar <idadesub at users.sourceforge.net>:

I noticed that io.StringIO is inconsistent with open on how newlines are 
handled. The default approach open uses is universal newlines:

>>> with open('foo', 'w') as f:
...   f.write('hello hi\r\nla la\r\n')
... 
17
>>> open('foo').readlines()
['hello hi\n', 'la la\n']

io.StringIO, however, defaults to just treating \n as newlines:

>>> io.StringIO('hello hi\r\nla la \r\n').readlines()
['hello hi\r\n', 'la la \r\n']

The attached patch changes this so that if the newline keyword isn't 
specified, then StringIO will act just like open with respect to 
keywords. It will then produce this:

>>> io.StringIO('hello hi\r\nla la \r\n').readlines()
['hello hi\n', 'la la \n']

----------
components: Library (Lib)
files: 0001-Make-StringIO-consistent-with-open-wrt-newlines.patch
keywords: patch
message_count: 1.0
messages: 83341
nosy: erickt
nosy_count: 1.0
severity: normal
status: open
title: patch to make io.StringIO consistent with open with respect to newlines
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file13276/0001-Make-StringIO-consistent-with-open-wrt-newlines.patch

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


More information about the New-bugs-announce mailing list