This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author erickt
Recipients erickt
Date 2009-03-09.00:09:53
SpamBayes Score 0.0037287816
Marked as misclassified No
Message-id <>
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')
>>> 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']
Date User Action Args
2009-03-09 00:09:54ericktsetrecipients: + erickt
2009-03-09 00:09:54ericktsetmessageid: <>
2009-03-09 00:09:53ericktlinkissue5451 messages
2009-03-09 00:09:53ericktcreate