On Tue, Aug 6, 2013 at 11:38 AM, Devyn Collier Johnson <devyncjohn...@gmail.com> wrote: > with open('/home/collier/pytest/sort.TXT') as file: > sorted(file, key=str.casefold, reverse=True) > > > Thanks for the advice Joshua. I find these tips very useful. However, how > would I close the files, or would they close after the "with" construct is > complete?
That's the whole point of 'with'. It calls open(), then calls __enter__, and it guarantees to call __exit__ before executing any code following the with block. With a file object, __exit__ will close the file. ChrisA -- http://mail.python.org/mailman/listinfo/python-list