]> granicus.if.org Git - python/commitdiff
Doc that file.next() has undefined behaviour when called on a file opened with
authorBrett Cannon <bcannon@gmail.com>
Sun, 8 Apr 2007 04:29:32 +0000 (04:29 +0000)
committerBrett Cannon <bcannon@gmail.com>
Sun, 8 Apr 2007 04:29:32 +0000 (04:29 +0000)
'w'.  Closes bug #1569057.

To be backported once 2.5 branch is unfrozen.

Doc/lib/libstdtypes.tex
Misc/NEWS

index 3cad43b301a6afa38e2b3e90c6b4ff4bac69c45b..0ad2ebcca3203b56a73f6ab6d4441ef65a10d091 100644 (file)
@@ -1615,14 +1615,15 @@ A file object is its own iterator, for example \code{iter(\var{f})} returns
 iterator, typically in a \keyword{for} loop (for example,
 \code{for line in f: print line}), the \method{next()} method is
 called repeatedly.  This method returns the next input line, or raises
-\exception{StopIteration} when \EOF{} is hit.  In order to make a
-\keyword{for} loop the most efficient way of looping over the lines of
-a file (a very common operation), the \method{next()} method uses a
-hidden read-ahead buffer.  As a consequence of using a read-ahead
-buffer, combining \method{next()} with other file methods (like
-\method{readline()}) does not work right.  However, using
-\method{seek()} to reposition the file to an absolute position will
-flush the read-ahead buffer.
+\exception{StopIteration} when \EOF{} is hit when the file is open for
+reading (behavior is undefined when the file is open for writing).  In
+order to make a \keyword{for} loop the most efficient way of looping
+over the lines of a file (a very common operation), the
+\method{next()} method uses a hidden read-ahead buffer.  As a
+consequence of using a read-ahead buffer, combining \method{next()}
+with other file methods (like \method{readline()}) does not work
+right.  However, using \method{seek()} to reposition the file to an
+absolute position will flush the read-ahead buffer.
 \versionadded{2.3}
 \end{methoddesc}
 
index 12d4413244650c031ce31dbbdf32d1360696c0f0..d15f673275c312d4df5057f7646cde49cac0c82a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -736,6 +736,9 @@ Tools
 Documentation
 -------------
 
+- Bug #1569057: Document that calling file.next() when the file is open for
+  writing is undefined.
+
 - Patch #1489771: the syntax rules in Python Reference Manual were
   updated to reflect the current Python syntax.