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.

classification
Title: Wrong detection of lines in readlines() function
Type: behavior Stage:
Components: None Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Miso.Kopera, eric.smith
Priority: normal Keywords:

Created on 2010-12-30 20:09 by Miso.Kopera, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
testFile Miso.Kopera, 2010-12-30 20:09 fail at this file
Messages (2)
msg124932 - (view) Author: (Miso.Kopera) Date: 2010-12-30 20:09
bug in "file.readlines()" function. It doesn't detect end of the line when line is ending only with 0x0D byte. In python3.1 it works fine (as I expect). File in attachment should has 6 lines not only 1 as python2.7 returns.
msg124934 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-12-30 20:22
Either use mode 'U' or the io module if you want to match 3.x.

$ python
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> open('testFile').readlines()
['# blaaaaa\r#\r\t# blaaaaaaaa\r\t#\r\t#\r#blaaa\t\r']
>>> open('testFile', 'U').readlines()
['# blaaaaa\n', '#\n', '\t# blaaaaaaaa\n', '\t#\n', '\t#\n', '#blaaa\t\n']
>>> import io
>>> io.open('testFile').readlines()
[u'# blaaaaa\n', u'#\n', u'\t# blaaaaaaaa\n', u'\t#\n', u'\t#\n', u'#blaaa\t\n']
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 55006
2010-12-30 20:22:20eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg124934

resolution: not a bug
2010-12-30 20:09:30Miso.Koperacreate