Python3 Os Lseek
# Python3.x Python3 os.lseek() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.lseek() method is used to set the current position of the file descriptor fd to pos, modified by the how parameter.
It is valid on Unix and Windows.
### Syntax
The syntax for the **lseek()** method is as follows:
os.lseek(fd, pos, how)
### Parameters
* **fd** -- The file descriptor.
* **pos** -- This is the position in the file relative to the given how parameter.
* **how** -- The reference position within the file. SEEK_SET or 0 sets the position from the beginning of the file; SEEK_CUR or 1 sets it from the current position; os.SEEK_END or 2 sets it from the end of the file.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the lseek() method:
#!/usr/bin/python3import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Write a string os.write(fd, "This is test")# Call fsync() method os.fsync(fd)# Read string from the beginning os.lseek(fd, 0, 0) str = os.read(fd, 100)print ("Read String is : ", str)# Close the file os.close( fd )print ("File closed successfully!!")
The output of the above program is:
File closed successfully!!
[ Python3 OS File/Directory Methods](#)
YouTip