Kaydet (Commit) 687ed47d authored tarafından Fred Drake's avatar Fred Drake

- 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)
üst 92dee4bc
...@@ -3069,6 +3069,15 @@ the file, returning \code{None}. ...@@ -3069,6 +3069,15 @@ the file, returning \code{None}.
>>> f.write('This is a test\n') >>> f.write('This is a test\n')
\end{verbatim} \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 \code{f.tell()} returns an integer giving the file object's current
position in the file, measured in bytes from the beginning of the position in the file, measured in bytes from the beginning of the
file. To change the file object's position, use file. To change the file object's position, use
...@@ -3081,7 +3090,7 @@ reference point. \var{from_what} can be omitted and defaults to 0, ...@@ -3081,7 +3090,7 @@ reference point. \var{from_what} can be omitted and defaults to 0,
using the beginning of the file as the reference point. using the beginning of the file as the reference point.
\begin{verbatim} \begin{verbatim}
>>> f=open('/tmp/workfile', 'r+') >>> f = open('/tmp/workfile', 'r+')
>>> f.write('0123456789abcdef') >>> f.write('0123456789abcdef')
>>> f.seek(5) # Go to the 6th byte in the file >>> f.seek(5) # Go to the 6th byte in the file
>>> f.read(1) >>> f.read(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment