[Python-checkins] python/dist/src/Doc/tut tut.tex,1.273,1.274
rhettinger@users.sourceforge.net
rhettinger at users.sourceforge.net
Tue Jun 28 02:16:12 CEST 2005
Update of /cvsroot/python/python/dist/src/Doc/tut
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19720
Modified Files:
tut.tex
Log Message:
Note that files are iterable.
Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.273
retrieving revision 1.274
diff -u -d -r1.273 -r1.274
--- tut.tex 27 Jun 2005 23:36:47 -0000 1.273
+++ tut.tex 28 Jun 2005 00:16:08 -0000 1.274
@@ -3166,6 +3166,21 @@
['This is the first line of the file.\n', 'Second line of the file\n']
\end{verbatim}
+An alternate approach to reading lines is to loop over the file object.
+This is memory efficient, fast, and leads to simpler code:
+
+\begin{verbatim}
+>>> for line in f:
+ print line,
+
+This is the first line of the file.
+Second line of the file
+\end{verbatim}
+
+The alternative approach is simpler but does not provide as fine-grained
+control. Since the two approaches manage line buffering differently,
+they should not be mixed.
+
\code{f.write(\var{string})} writes the contents of \var{string} to
the file, returning \code{None}.
More information about the Python-checkins
mailing list