Issue 33229: Documentation - io — Core tools for working with streams - seek() (original) (raw)

As indicated in the seek docs ( https://docs.python.org/3/library/io.html#io.IOBase.seek ), all three names were added to the io module in 3.1:

New in version 3.1: The SEEK_* constants.

Since they're part of the io module too, there is no need to qualify them on the io module docs page.

They're available in os as well, but you don't need to import it to use them. The OS specific addition position flags are explicitly documented to be found on the os module.

Seems in my, quite old 3.4.5 version, it doesn't work:

$ python3 Python 3.4.5 (default, Jun 1 2017, 13:52:39) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information.

f = open('/tmp/text.txt', 'r') f.seek(0, SEEK_END) Traceback (most recent call last): File "", line 1, in NameError: name 'SEEK_END' is not defined f.close()

import os f = open('/tmp/text.txt', 'r') f.seek(0, os.SEEK_END) 214 f.close()