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: codecs: readline() followed by readlines() returns trunkated results
Type: behavior Stage: resolved
Components: IO, Unicode Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: When I use codecs.open(...) and f.readline() follow up by f.read() return bad result
View: 8260
Assigned To: Nosy List: ezio.melotti, laurynas, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-12-07 17:01 by laurynas, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sample_text.txt laurynas, 2012-12-07 17:01 Sample text file that breaks codecs.readlines()
Messages (3)
msg177098 - (view) Author: Laurynas Speicys (laurynas) Date: 2012-12-07 17:01
codecs.readlines() does not read to the end of the file if called after codecs.readline().  

Skimmed through tasks containing codecs in title and could not find a candidate that sounded identical.

Repro follows:

$ cat sample_text.txt
Subject: Incorrect email address
 
RATER EMAIL rejected an invitation from SUBJECT NAME <SUBJECT EMAIL> in
the PROJECT TITLE project.  Notification was sent to <RECIPIENT EMAIL>,
but the email address was no longer valid.


$ python
Python 2.7.3 (default, Sep 26 2012, 21:53:58) 
[GCC 4.7.2] on linux2
>>>
>>> import codecs
>>>
>>> # No problem if readlines() are run at the beginning:
>>>
>>> f_in = codecs.open('sample_text.txt', 'rb', 'utf-8')
>>> f_in.readlines()
[u'Subject: Incorrect email address\n', u'\n', u'RATER EMAIL rejected an invitation from SUBJECT NAME <SUBJECT EMAIL> in\n', u'the PROJECT TITLE project.  Notification was sent to <RECIPIENT EMAIL>,\n', u'but the email address was no longer valid.']
>>> f_in.close()
>>>
>>> # Let us try to read the first line separately,
>>> # and then read the remainder of the file:
>>>
>>> f_in = codecs.open('sample_text.txt', 'rb', 'utf-8')
>>> f_in.readline()
u'Subject: Incorrect email address\n'
>>> f_in.readlines()
[u'\n', u'RATER EMAIL rejected an invitation fro']

The first readlines() does not read to the end. Subsequent readlines() returns what's left to read.

sample_text.txt attached.
msg177102 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-07 17:34
Confirm for 3.x.

See also issue8260, issue12446, and issue14475.
msg177111 - (view) Author: Laurynas Speicys (laurynas) Date: 2012-12-07 18:53
Thank you! This is indeed a duplicate of issues #8260, #12446.
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60840
2012-12-07 20:03:53serhiy.storchakasetstatus: open -> closed
superseder: When I use codecs.open(...) and f.readline() follow up by f.read() return bad result
stage: needs patch -> resolved
2012-12-07 18:53:45laurynassetresolution: duplicate
messages: + msg177111
2012-12-07 17:34:36serhiy.storchakasetversions: + Python 3.2, Python 3.3, Python 3.4
nosy: + ezio.melotti, serhiy.storchaka

messages: + msg177102

components: + Unicode, IO
stage: needs patch
2012-12-07 17:01:38laurynascreate