Python seek() Method29 Aug 2024 | 3 min read Python seek() method is used for changing the current location of the file handle. The file handle is like a cursor, which is used for defining the location of the data which has to be read or written in the file. Syntax:Parameters:Offset: This is used for defining the number of positions to move forward. from_where: This is used for defining the point of reference. NOTE: The seek() method in Python does not return any value.The from_where argument is used for selecting the reference point. It can accept three values:
The from_where argument is set to 0 by default. Therefore, the reference point cannot be set to the current position or end position, in the text mode, except when the offset is equal to 0. Example1: (The user has to read the text file, which contains the following text: "This is the sentence I am Writing to show the example of the seek() method working in Python." Output: 30 ing to show the example of the seek() method working in Python. Sample Text File - Example 2: (method 2) Output: Name of the file: text.txt Read Line: This is the sentence I am Writing to show the example of the seek() method working in Python. Read Line: The line no. 2 for showing the second method of writing the seek() method is python The seek() method can also work with the negative offset, but only when the file is opened in binary mode. Example 3: (negative offset) Output: 25 Writing to show the example of the seek() method working in Python. Next TopicTernary Operator in Python |
In this article, we'll examine a variety of Python programs that let us quickly spot duplicate sets among a list of sets. To complete this task, we will make use of Python's robust set operations and functional programming features. We will also go over several techniques...
10 min read
What is a Binary Search Tree? A binary tree is a binary data structure containing different nodes in which each node has at most two child nodes. These nodes follow some properties, including: The left nodes of the binary tree have a lesser value than the root node. The...
5 min read
When and How to Use StandardScaler? When the features of the given dataset fluctuate significantly within their ranges or are recorded in various units of measurement, StandardScaler enters the picture. The data are scaled to a variance of 1 after the mean is reduced to 0 via StandardScaler....
4 min read
Web Scraping is a process of scraping webpages and extracting details from them. Instead of regularly copying and pasting information from the web pages for a project, web scraping can be effective for this problem. But, there are few websites available for web scraping. There are...
3 min read
An array is a collection of linear data structures that contain all elements of the same data type in contiguous memory space. It is like a container that holds a certain number of elements that have the same data type. An array's index starts at 0,...
6 min read
In this tutorial, we will discuss how we can download files from the web using the third-party library in Python. We will also explore the stream data to download large files in manageable chunks and implement parallel downloads using a pool of threads. Python provides a comprehensive...
9 min read
In this tutorial, we will learn how we can create a vector using Numpy library. We will also explore basic operation of vector such as performing addition of two vectors, subtraction of two vectors, division of two vectors, multiplication of two vectors, vector dot product and...
5 min read
Using binary search, we can find an element in the given sorted array or list in O(log(n)) time complexity, where n is the number of the numbers in the list. Now let us rotate this sorted array or list at any pivot. However, we don't know...
7 min read
Decorators are useful tool of the Python as they are used to modify the behavior of the function without permanently changing it. We have explained decorators in details in our decorator in Python tutorial. In this tutorial, we will learn about the dispatch decorators and its...
3 min read
In this tutorial, we will learn how we can detect if given strings are anagram. But first we should familiar with the anagram's concept. What is Anagram? An Anagram is a condition where one string or number is rearranged in that manner; each character of the rearranged string...
5 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India