Comment

Comment by codefisher

The equivalent code with out the context manager is actually this:

  f = open('foo.txt')
  try:
     contents = f.read()
  finally:
     f.close()
So yes, extra reason to prefer the context manager.
parent codefisher 11 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton