Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e808c23

Browse files
committed
- show how to use file.write() with a non-string value
(closes SF bug #621057) - add missing whitespace around assignment operator
1 parent 22b3b47 commit e808c23

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Doc/tut/tut.tex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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
31613170
position in the file, measured in bytes from the beginning of the
31623171
file. To change the file object's position, use
@@ -3169,7 +3178,7 @@ \subsection{Methods of File Objects \label{fileMethods}}
31693178
using 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)

0 commit comments

Comments
 (0)