File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3157,6 +3157,15 @@ \subsection{Methods of File Objects \label{fileMethods}}
31573157>>> f.write('This is a test\n')
31583158\end {verbatim }
31593159
3160+ To write something other than a string, it needs to be converted to a
3161+ string first:
3162+
3163+ \begin {verbatim }
3164+ >>> value = ('the answer', 42)
3165+ >>> s = str(value)
3166+ >>> f.write(s)
3167+ \end {verbatim }
3168+
31603169\code {f.tell()} returns an integer giving the file object's current
31613170position in the file, measured in bytes from the beginning of the
31623171file. To change the file object's position, use
@@ -3169,7 +3178,7 @@ \subsection{Methods of File Objects \label{fileMethods}}
31693178using the beginning of the file as the reference point.
31703179
31713180\begin {verbatim }
3172- >>> f= open('/tmp/workfile', 'r+')
3181+ >>> f = open('/tmp/workfile', 'r+')
31733182>>> f.write('0123456789abcdef')
31743183>>> f.seek(5) # Go to the 6th byte in the file
31753184>>> f.read(1)
You can’t perform that action at this time.
0 commit comments