Python Practice › File Handling Programs › Program 31
Cursor position with tell()
Write a Python program to find the current cursor position in a file.
Output
0 5
Approach
tell()returns the position in bytes from the start.
Solution
with open("story.txt", "w") as f: f.write("Hello Python\n") with open("story.txt") as f: print(f.tell()) f.read(5) print(f.tell())Output
0 5
Learn the concept
New to this topic? Read the lesson, then come back.