OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.lseek() method sets the current position of file descriptor fd to the given position pos which is modified by how.
Syntax: os.lseek(fd, pos, how) Parameters: fd: This is the file descriptor on which seek is to be performed. pos: This is the position in the file with respect to given parameter how. It can accept three values which are
- os.SEEK_SET or 0 to set the position relative to the beginning of the file
- os.SEEK_CUR or 1 to set the position relative to the current position
- os.SEEK_END or 2 to set the position relative to the end of the file.
- os.SEEK_SET or 0 to set the reference point to the beginning of the file
- os.SEEK_CUR or 1 to set the reference point to the current position
- os.SEEK_END or 2 to set the reference point to the end of the file.
os.lseek()method to seek the file from beginning
Example #2 :
os.lseek() method to to seek the file from specific position
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course