all Python 3osfunction
os.lseek
os — file descriptors
Move a descriptor's read/write position and return the new offset.
Syntax
os.lseek(fd, pos, whence)
It returns the new position, so lseek(fd, 0, os.SEEK_END) is a quick way to get an open file's size and lseek(fd, 0, os.SEEK_CUR) gives the current position. All copies of the descriptor made by dup or inheritance share the position. Seeking past the end does not grow the file by itself — only a subsequent write does.
Examples
import os
fd = os.open(os.__file__, os.O_RDONLY)
os.lseek(fd, 0, os.SEEK_END)
print(os.lseek(fd, 0, os.SEEK_CUR) > 0) # → True
os.close(fd)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy