Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d60818da
Commit
d60818da
authored
Jul 30, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#16273: Fix tutorial discussion of seek/tell (opaque text-mode values).
Patch by Sijin Joseph.
parent
04a23878
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
Doc/tutorial/inputoutput.rst
Doc/tutorial/inputoutput.rst
+9
-4
No files found.
Doc/tutorial/inputoutput.rst
View file @
d60818da
...
@@ -322,9 +322,11 @@ first::
...
@@ -322,9 +322,11 @@ first::
>>> f.write(s)
>>> f.write(s)
18
18
``f.tell()`` returns an integer giving the file object's current position in the
``f.tell()`` returns an integer giving the file object's current position in the file
file, measured in bytes from the beginning of the file. To change the file
represented as number of bytes from the beginning of the file when in `binary mode` and
object's position, use ``f.seek(offset, from_what)``. The position is computed
an opaque number when in `text mode`.
To change the file object's position, use ``f.seek(offset, from_what)``. The position is computed
from adding *offset* to a reference point; the reference point is selected by
from adding *offset* to a reference point; the reference point is selected by
the *from_what* argument. A *from_what* value of 0 measures from the beginning
the *from_what* argument. A *from_what* value of 0 measures from the beginning
of the file, 1 uses the current file position, and 2 uses the end of the file as
of the file, 1 uses the current file position, and 2 uses the end of the file as
...
@@ -345,7 +347,10 @@ beginning of the file as the reference point. ::
...
@@ -345,7 +347,10 @@ beginning of the file as the reference point. ::
In text files (those opened without a ``b`` in the mode string), only seeks
In text files (those opened without a ``b`` in the mode string), only seeks
relative to the beginning of the file are allowed (the exception being seeking
relative to the beginning of the file are allowed (the exception being seeking
to the very file end with ``seek(0, 2)``).
to the very file end with ``seek(0, 2)``) and the only valid *offset* values are
those returned from the ``f.tell()``, or zero. Any other *offset* value produces
undefined behaviour.
When you're done with a file, call ``f.close()`` to close it and free up any
When you're done with a file, call ``f.close()`` to close it and free up any
system resources taken up by the open file. After calling ``f.close()``,
system resources taken up by the open file. After calling ``f.close()``,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment