---
title: "Python Logic to use tell() and seek()"
description: "In Python, both tell and seek functions help you get the data from a file. How to use these explained on how to use in your current project."
url: https://srinimf.com/2021/04/04/python-logic-to-use-tell-and-seek/
date: 2021-04-04
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/04/pexels-photo-534124.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["Python tell and seek functions"]
type: post
lang: en
---

# Python Logic to use tell() and seek()

Here i[s all about](https://srinimf.com/2020/03/07/queues-vs-process-linux/) tell and seek in Python. Using **tell (),** you will get the current position in the file, and you can set it as you wish using **seek()**.

## **Tell and Seek in Python**

Advertisements

## Logic to Use tell()

The current position in the file can be known with the help of ‘tell()’ function. It returns the file object’s present position in the form of an integer. In binary mode, the position is represented as the number of bytes from the beginning of the file. In text mode, the position is represented as an opaque number.

```
Initially the text in the file is "I AM READY"
>>> str=myfile.read(10) 
Result is "I AM READY"

>>> pos=myfile.tell()
>>> print("present position of the file: ", pos)
Result
present position of the file: 10
```

![Python Logic to use tell() and seek()](https://i0.wp.com/srinimf.com/wp-content/uploads/2021/04/pexels-photo-6599578.jpeg?resize=434%2C650&ssl=1)*Photo by Tima Miroshnichenko on Pexels.com*

## Logic to Use seek()

The current position of the file can be changed with the help of the ‘seek()’ function. It indicates the number of bytes to be moved and the point from where the bytes must move.

**Syntax:** ‘seek(offset[, from])‘

Here,

- The ‘offset’ argument specifies the number of bytes to be moved.
- The ‘from’ argument indicates the reference position, starting from where the bytes are to be moved.
- The file beginning is used as the reference position if ‘from’ is set as 0.
- The current file position is used as the reference position if ‘from’ is set as 1.
- The file end is used as the reference position if ‘from’ is set as 2.

```
I am now changing the offset and from position
>>> pos=myfile.seek(0,0)
>>> print("The text from updated position: ", pos)
The text from updated position: I AM READY
```

Related Posts

[![Python Theory Questions for Interviews](https://i0.wp.com/srinimf.com/wp-content/uploads/2025/11/pexels-photo-5428835.jpeg?fit=401%2C600&ssl=1)](https://srinimf.com/2025/11/14/python-theory-questions-for-interviews/)

### [Python Theory Questions for Interviews](https://srinimf.com/2025/11/14/python-theory-questions-for-interviews/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
November 14, 2025

[![Top 8 Python Data Engineering Interview Questions with SQL and Pandas Solutions](https://i0.wp.com/srinimf.com/wp-content/uploads/2025/10/pexels-photo-11674340.jpeg?fit=400%2C600&ssl=1)](https://srinimf.com/2025/10/07/top-8-python-data-engineering-interview-questions-with-sql-and-pandas-solutions/)

### [Top 8 Python Data Engineering Interview Questions with SQL and Pandas Solutions](https://srinimf.com/2025/10/07/top-8-python-data-engineering-interview-questions-with-sql-and-pandas-solutions/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
October 7, 2025

[![Python Interview Prep in 1 Hour: 12 Essential Coding Programs](https://i0.wp.com/srinimf.com/wp-content/uploads/2025/09/pexels-photo-8378723.jpeg?fit=600%2C400&ssl=1)](https://srinimf.com/2025/09/10/python-interview-prep-in-1-hour-12-essential-coding-programs/)

### [Python Interview Prep in 1 Hour: 12 Essential Coding Programs](https://srinimf.com/2025/09/10/python-interview-prep-in-1-hour-12-essential-coding-programs/)

[![Srini&apos;s avatar](https://secure.gravatar.com/avatar/f10b4bafeeb96dce9806c5a3c6cde6ea1e2c014ef273120a4bf2c6d5f975f01c?s=48&r=g)](https://srinimf.com/author/moonrobot/)
by [Srini](https://srinimf.com/author/moonrobot/)
September 10, 2025

Keep Reading

- [How to Find Databricks Job Status, Owner, and Active Runs Fast](https://srinimf.com/2026/10/17/databricks-find-job-status/)
- [30 SQL Practice Queries with Solutions — Run Them Live](https://srinimf.com/2026/10/01/30-sql-practice-queries-with-solutions-run-them-live/)
- [Supercharge Your Database Skills: Try Our New Interactive SQL Plugin!](https://srinimf.com/2026/09/30/supercharge-your-database-skills-try-our-new-interactive-sql-plugin/)

References

- [How to control position while reading from a file](https://python-reference.readthedocs.io/en/latest/docs/file/seek.html)
- [Binary Vs Text File in Python](https://dbader.org/blog/python-file-io)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F04%2F04%2Fpython-logic-to-use-tell-and-seek%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F04%2Fpexels-photo-534124.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Python%20Logic%20to%20use%20tell%28%29%20and%20seek%28%29)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/04/04/python-logic-to-use-tell-and-seek/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/04/04/python-logic-to-use-tell-and-seek/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/04/04/python-logic-to-use-tell-and-seek/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/04/04/python-logic-to-use-tell-and-seek/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Python%20Logic%20to%20use%20tell%28%29%20and%20seek%28%29&body=https%3A%2F%2Fsrinimf.com%2F2021%2F04%2F04%2Fpython-logic-to-use-tell-and-seek%2F&share=email)
-

### Like this:

Like Loading…