On 2/16/2016 3:39 AM, jf...@ms4.hinet.net wrote:
I know

     with open('foo.txt') as f:
         ...do something...

will close the file automatically when the "with" block ends.

I also saw codes in a book:

     for line in open('foo.txt'):
        ...do something...

Some books were originally written before 'with context_manager' was added, or a little later, before it became the normal thing to do.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to