Skip to content
File Methods

seekable()

Return True if the file stream supports random access positioning.

file.seekable()

file.seekable() checks whether the file object supports random access seek operations (like seek(), tell(), and truncate()).

Disk files are seekable, while streams, pipes, and sockets are generally not.

Returns

True if seekable; otherwise False.

Try it

Run it and change it
import tempfile
with tempfile.NamedTemporaryFile(mode='w+', delete=True) as f:
    print('Is disk file seekable:', f.seekable())

Worth knowing

  • Error prevention: Calling seek() on a non-seekable stream (like sys.stdin) raises an io.UnsupportedOperation exception.

Related entries