Easy Tutorial
❮ Python Count Occurrences Element List Ref Math Isfinite ❯

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 how.

This method is valid on Unix and Windows systems.

Syntax

The syntax for the lseek() method is as follows:

os.lseek(fd, pos, how)

Parameters

Return Value

This method does not return a value.

Example

The following example demonstrates the use of the lseek() method:

#!/usr/bin/python3

import 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")

# Flush all fsync() methods
os.fsync(fd)

# Read the string from the start position
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!!")

Executing the above program outputs:

File closed successfully!!

Python3 OS File/Directory Methods

❮ Python Count Occurrences Element List Ref Math Isfinite ❯