Python File seek() Method
Dabbanci
Change the current file position to 4 and return the rest of the lines:
f = open("demofile.txt", "r") f.seek(4) print(f.readline())
Definition and Usage
seek() method sets the current file position in the file stream.
seek() method also returns the new position.
Syntax
file.seek(Offset)
Parameter Value
Parameter | Description |
---|---|
Offset | Mandatory. Numeric value, indicating the position to set the current file stream position. |
More Dabbanci
Dabbanci
Return New Position:
f = open("demofile.txt", "r") print(f.seek(4))