Chapters
Python114 chapters

ReferenceFile methods

file.seek()

Moves the read position, usually back to the start.

Signature

f.seek(offset)

Parameters

NameMeans
offsetwhere to move to, in bytes from the beginning

Returns

The new position.

Example

Python
with open("notes.txt", "w", encoding="utf-8") as f:
    f.write("Ada")

with open("notes.txt", encoding="utf-8") as f:
    print(f.read())
    print(repr(f.read()))
    f.seek(0)
    print(f.read())

Output

Ada
''
Ada

See also