On Thu, Apr 30, 2015 at 7:06 PM, Cecil Westerhof <ce...@decebal.nl> wrote: > I already done it. I thought it not to much work. And it even makes > some code shorter: > - marshal_file = open(expanduser(marshal_filename), 'r') > - not_list = load(marshal_file) > - marshal_file.close() > - return not_list > + with open(expanduser(marshal_filename), 'r') as f: > + return load(f) > > But here I did the close myself already, so that is not completely > honest of me. ;-)
The context manager makes your code more concise AND more reliable - an exception thrown by load() will skip the explicit close(), but the 'with' block unwinds correctly whether there's an exception or not. ChrisA -- https://mail.python.org/mailman/listinfo/python-list