The f.seek() and f.tell() methods are typically used to manipulate the current position within a file, but they are not necessary for reading each line of a file sequentially.
To read each line of a file, you can use a loop with the readline() method. Here's an updated version of your code to achieve that:
f = open('test.txt', 'r')
for line in f.readlines():
print(line)
f.close()
In this code, f.readlines() returns a list containing all the lines in the file. The loop then iterates over each line and prints it. Finally, don't forget to close the file using f.close() to release system resources.
Alternatively, you can use a more concise and recommended approach using a with statement, which automatically takes care of closing the file for you:
with open('test.txt', 'r') as f:
for line in f.readlines():
print(line)
This with statement ensures the file is properly closed even if an exception occurs during the file operations.