Python

Python Menu

Definition

The seek() method sets the current file position in a file stream. This method also returns the new position.

Syntax

file.seek(offset)

Parameters

Parameter Description
offset Required. A number representing the position to set the current file stream position.

Examples:

# Change the current file position to 4, and return the rest of the line
f = open("demofile.txt", "r")
f.seek(4)
print(f.readline())

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods