for i in range(3): fil = open('data.txt') fil.readlines() # the result should be freed here already fil.close()