This closes the file after reading data. Once a file has been opened, you should always close it after reading or writing data to it. A better solution is to use a context manager:
with open(filename) as file:
data = file.read()
# The file will automatically be closed after the above line
This closes the file after reading data. Once a file has been opened, you should always close it after reading or writing data to it. A better solution is to use a context manager: