diff --git a/Doc/library/io.rst b/Doc/library/io.rst index e06ab3fd89b..9e4161a2336 100644 --- a/Doc/library/io.rst +++ b/Doc/library/io.rst @@ -270,12 +270,18 @@ I/O Base Classes interpreted relative to the position indicated by *whence*. Values for *whence* are: - * ``0`` -- start of the stream (the default); *offset* should be zero or positive - * ``1`` -- current stream position; *offset* may be negative - * ``2`` -- end of the stream; *offset* is usually negative + * :data:`SEEK_SET` or ``0`` -- start of the stream (the default); + *offset* should be zero or positive + * :data:`SEEK_CUR` or ``1`` -- current stream position; *offset* may + be negative + * :data:`SEEK_END` or ``2`` -- end of the stream; *offset* is usually + negative Return the new absolute position. + .. versionadded:: 2.7 + The ``SEEK_*`` constants + .. method:: seekable() Return ``True`` if the stream supports random access. If ``False``, diff --git a/Lib/io.py b/Lib/io.py index 8a8cf699af6..56ceb58ce10 100644 --- a/Lib/io.py +++ b/Lib/io.py @@ -52,7 +52,8 @@ __author__ = ("Guido van Rossum , " __all__ = ["BlockingIOError", "open", "IOBase", "RawIOBase", "FileIO", "BytesIO", "StringIO", "BufferedIOBase", "BufferedReader", "BufferedWriter", "BufferedRWPair", - "BufferedRandom", "TextIOBase", "TextIOWrapper"] + "BufferedRandom", "TextIOBase", "TextIOWrapper", + "SEEK_SET", "SEEK_CUR", "SEEK_END"] import _io @@ -65,6 +66,11 @@ from _io import (DEFAULT_BUFFER_SIZE, BlockingIOError, UnsupportedOperation, OpenWrapper = _io.open # for compatibility with _pyio +# for seek() +SEEK_SET = 0 +SEEK_CUR = 1 +SEEK_END = 2 + # Declaring ABCs in C is tricky so we do it here. # Method descriptions and default implementations are inherited from the C # version however.