What is the python "with" statement designed for?

Posted by fmark on Stack Overflow See other posts from Stack Overflow or by fmark
Published on 2010-06-10T07:35:21Z Indexed on 2010/06/10 7:52 UTC
Read the original article Hit count: 513

I came across the Python with statement for the first time today. I've been using Python lightly for several months and didn't even of its existence! Given its somewhat obscure status, I thought it would be worth asking:

  1. What is the Python with statement designed to be used for?
  2. What do you use it for?
  3. Are their any gotchas I need to be aware of, or common anti-patterns associated with its use?

© Stack Overflow or respective owner

Related posts about python

Related posts about best-practices