[ python-Bugs-1036626 ] file.next() info hidden

SourceForge.net noreply at sourceforge.net
Sun Nov 7 19:55:26 CET 2004


Bugs item #1036626, was opened at 2004-09-28 22:42
Message generated for change (Comment added) made by rodsenra
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1036626&group_id=5470

Category: Documentation
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Jacobson (nickjacobson)
Assigned to: Nobody/Anonymous (nobody)
Summary: file.next() info hidden

Initial Comment:
(A.M. Kuchling told me to post this bug report.)

In section 2.3.8, "File Objects", of the Python Library 
Reference, the following section is given for file.next():

<<
In order to make a for loop the most efficient way of 
looping over the lines of a file (a very common 
operation), the next() method uses a hidden read-ahead 
buffer. As a consequence of using a read-ahead buffer, 
combining next() with other file methods (like readline()) 
does not work right.
>>

This information is necessary for anyone who mixes "for 
line in file:" with read()/tell()/etc.  However, in the 
statement "for line in file:", next() is called implicitly, and 
therefore it may not occur to the programmer to find the 
information there.

Therefore the documentation should be reorganized.
One solution is to have the read()/tell()/etc. methods 
refer to the above section.  i.e. "Don't use this method 
with next() or 'for line in file:'; see next()."

A second solution is to move the above section to 
before the methods section (i.e. after the second 
paragraph after the 2.3.8 header), and to mention 'for 
line in file:'.
i.e. "As a consequence of using a read-ahead buffer, 
combining next() or 'for line in file:' with other file 
methods (like readline()) does not work right."

(Also, saying "with other file methods (like readline())" is 
too vague.  IMHO it should specify which ones not to 
use.  That's debatable though.)


----------------------------------------------------------------------

Comment By: Rodrigo Dias Arruda Senra (rodsenra)
Date: 2004-11-07 18:55

Message:
Logged In: YES 
user_id=9057

I agree this should be closed without any modification to
the docs.
The information that clarifies the matter is under "File
Objects", where
anybody with doubts about "for i in fileobject:" should look
for. 

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-10-27 17:22

Message:
Logged In: YES 
user_id=80475

IMO, the docs are fine as-is.  Sometimes, trying to be over
specific makes the docs less usable rather than more.  The
current wording pretty much covers why the iterator protocol
is at odds with the readline() style methods.

Of course, this could be argued to death.  So, I'll leave
the report open so that others can express their take.

----------------------------------------------------------------------

Comment By: engelbert gruber (grubert)
Date: 2004-10-05 13:55

Message:
Logged In: YES 
user_id=147070

see also http://www.python.org/sf/645594 for lin in file: file.tell() tells wrong

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1036626&group_id=5470


More information about the Python-bugs-list mailing list