The Python with statement creates a runtime context that allows you to run a group of statements under the control of a context manager.
Context manager is a mechanism for the automatic setup and teardown of resources - in this case for open files.
with open("data.txt") as f:
for line in f:
print(line.strip())
So, there is no need of f.close()