Home >>Python File Methods >Python File seek() Method
The seek() method is an inbuilt method in python, and is used to set the current file position at the offset handle to a given specific position. This method helps to return the new position.
Syntax:file.seek(offset)
Parameter | Description |
---|---|
offset | It is Required and is used to set the current file position. |
z = open("demofile.txt", "r")
z.seek(2)
print(z.readline())
x = open("demofile1.txt", "r")
x.seek(4)
print(x.readline())