This Python program receives the name of a text file, reads its content, and displays it line by line.
If the file contains more than 32 lines, the program pauses after every 32 lines and waits for the user to press a key to continue.
This is useful for paginated viewing of large files in the terminal.
import os
# Get file path from user
file_path = input("Enter the path to the text file: ")
# Check if file exists
if not os.path.isfile(file_path):
print("File not found.")
exit()
# Read and display lines with pause after every 32
with open(file_path, "r", encoding="utf-8") as f:
lines = f.readlines()
for i, line in enumerate(lines, start=1):
print(line.strip())
if i % 32 == 0:
input("\n--- Press Enter to continue ---\n")
Line 1: ...
Line 2: ...
...
Line 32: ...
--- Press Enter to continue ---
Line 33: ...
...
- The file path is received using input()
- os.path.isfile() checks if the file exists
- The file is read using readlines()
- A loop prints each line, and pauses every 32 lines using input()
- This allows the user to read large files in chunks without overwhelming the screen