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 know of its existence! Given its somewhat obscure status, I thought it would be worth asking:
- What is the Python
withstatement designed to be used for?
- What do you use it for?
- Are there any
gotchas I need to be aware of, or
common anti-patterns associated with
its use? Any cases where it is better use
- Why isn't it used more widely?
- Which standard library classes are compatible with it?