diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-07-30 19:53:30 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-07-30 19:53:30 (GMT) |
commit | bc47d7bb4f43674fcf7bd85f4ef36c5c6020930c (patch) | |
tree | 2c5bb2bf86e34fb414d42aba02caa4538a1be9c7 /Doc/tutorial | |
parent | f392c604e707d547753e8b0ebd94a06202d1b75f (diff) | |
parent | 1c4e443ea24e34713ae6957c36875cf983824693 (diff) | |
download | cpython-bc47d7bb4f43674fcf7bd85f4ef36c5c6020930c.zip cpython-bc47d7bb4f43674fcf7bd85f4ef36c5c6020930c.tar.gz cpython-bc47d7bb4f43674fcf7bd85f4ef36c5c6020930c.tar.bz2 |
Merge: #16273: Fix tutorial discussion of seek/tell (opaque text-mode values).
Diffstat (limited to 'Doc/tutorial')
-rw-r--r-- | Doc/tutorial/inputoutput.rst | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst index 744abab..7daf89b 100644 --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -322,9 +322,11 @@ first:: >>> f.write(s) 18 -``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 ``f.seek(offset, from_what)``. The position is computed +``f.tell()`` returns an integer giving the file object's current position in the file +represented as number of bytes from the beginning of the file when in `binary mode` and +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 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 @@ -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 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 system resources taken up by the open file. After calling ``f.close()``, |