diff options
author | Erlend E. Aasland <erlend@python.org> | 2023-08-22 10:01:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-22 10:01:38 (GMT) |
commit | ef4d427fd8ed89fcfb5a0fada4c24abec12991e5 (patch) | |
tree | 2daf8f740526f8c518fa7325c10e3c1d0301c392 /Doc/library/io.rst | |
parent | dd73f2f76ab1eabe92a2ca820430be723df31cde (diff) | |
download | cpython-ef4d427fd8ed89fcfb5a0fada4c24abec12991e5.zip cpython-ef4d427fd8ed89fcfb5a0fada4c24abec12991e5.tar.gz cpython-ef4d427fd8ed89fcfb5a0fada4c24abec12991e5.tar.bz2 |
[3.12] gh-107801: Improve the accuracy of io.TextIOWrapper.seek docs (#107933) (#108262)
(cherry picked from commit 7f87ebbc3f52680c939791f397b9a478edf0c8d4)
Clearly document the supported seek() operations:
- Rewind to the start of the stream
- Restore a previous stream position (given by tell())
- Fast-forward to the end of the stream
Diffstat (limited to 'Doc/library/io.rst')
-rw-r--r-- | Doc/library/io.rst | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Doc/library/io.rst b/Doc/library/io.rst index 66273d9..792bf43 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -1044,6 +1044,22 @@ Text I/O .. versionchanged:: 3.11 The method supports ``encoding="locale"`` option. + .. method:: seek(cookie, whence=os.SEEK_SET, /) + + Set the stream position. + Return the new stream position as an :class:`int`. + + Four operations are supported, + given by the following argument combinations: + + * ``seek(0, SEEK_SET)``: Rewind to the start of the stream. + * ``seek(cookie, SEEK_SET)``: Restore a previous position; + *cookie* **must be** a number returned by :meth:`!tell`. + * ``seek(0, SEEK_END)``: Fast-forward to the end of the stream. + * ``seek(0, SEEK_CUR)``: Leave the current stream position unchanged. + + Any other argument combinations are invalid, + and may raise exceptions. .. class:: StringIO(initial_value='', newline='\n') |