[Python-checkins] python/dist/src/Doc/tut tut.tex, 1.196.8.23,
1.196.8.24
fdrake at users.sourceforge.net
fdrake at users.sourceforge.net
Tue Nov 2 19:26:07 CET 2004
Update of /cvsroot/python/python/dist/src/Doc/tut
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31095
Modified Files:
Tag: release23-maint
tut.tex
Log Message:
- show how to use file.write() with a non-string value
(closes SF bug #621057)
- add missing whitespace around assignment operator
(backported from trunk revision 1.257)
Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.196.8.23
retrieving revision 1.196.8.24
diff -u -d -r1.196.8.23 -r1.196.8.24
--- tut.tex 22 Aug 2004 15:27:16 -0000 1.196.8.23
+++ tut.tex 2 Nov 2004 18:26:05 -0000 1.196.8.24
@@ -3069,6 +3069,15 @@
>>> f.write('This is a test\n')
\end{verbatim}
+To write something other than a string, it needs to be converted to a
+string first:
+
+\begin{verbatim}
+>>> value = ('the answer', 42)
+>>> s = str(value)
+>>> f.write(s)
+\end{verbatim}
+
\code{f.tell()} returns an integer giving the file object's current
position in the file, measured in bytes from the beginning of the
file. To change the file object's position, use
@@ -3081,7 +3090,7 @@
using the beginning of the file as the reference point.
\begin{verbatim}
->>> f=open('/tmp/workfile', 'r+')
+>>> f = open('/tmp/workfile', 'r+')
>>> f.write('0123456789abcdef')
>>> f.seek(5) # Go to the 6th byte in the file
>>> f.read(1)
More information about the Python-checkins
mailing list