Autoclose file after reading

The below code snippet demonstrates how to open a file, read line by line and auto close the file:

with open('file.txt') as the_file:
     for line in the_file:
         print(line.rstrip())

Author: Dean Capps

Database consultant at Amazon Web Services.