diff options
author | Fred Drake <fdrake@acm.org> | 2004-11-02 18:24:26 (GMT) |
---|---|---|
committer | Fred Drake <fdrake@acm.org> | 2004-11-02 18:24:26 (GMT) |
commit | e808c2341b4d6d1fb2d889241a8e899c5cf09cbf (patch) | |
tree | e44a16f0218d22aa334ec3c8d917a10aafe8c771 | |
parent | 22b3b47e23569c6d6ed1e37ecc1d470e947d0400 (diff) | |
download | cpython-e808c2341b4d6d1fb2d889241a8e899c5cf09cbf.zip cpython-e808c2341b4d6d1fb2d889241a8e899c5cf09cbf.tar.gz cpython-e808c2341b4d6d1fb2d889241a8e899c5cf09cbf.tar.bz2 |
- show how to use file.write() with a non-string value
(closes SF bug #621057)
- add missing whitespace around assignment operator
-rw-r--r-- | Doc/tut/tut.tex | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index eeca1d2..1794ba4 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -3157,6 +3157,15 @@ the file, returning \code{None}. >>> 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 @@ -3169,7 +3178,7 @@ reference point. \var{from_what} can be omitted and defaults to 0, 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) |