Top "With-statement" questions

A number of languages have With statements.

Explaining Python's '__enter__' and '__exit__'

I saw this in someone's code. What does it mean? def __enter__(self): return self def __exit__(self, type, value, …

python oop with-statement
Django {% with %} tags within {% if %} {% else %} tags?

So I want to do something like follows: {% if age > 18 %} {% with patient as p %} {% else %} {% with patient.parent as …

django templates with-statement if-statement
Multiple variables in a 'with' statement?

Is it possible to declare more than one variable using a with statement in Python? Something like: from __future__ import …

python with-statement
How do I mock an open used in a with statement (using the Mock framework in Python)?

How do I test the following code with unittest.mock: def testme(filepath): with open(filepath) as f: return f.…

python mocking with-statement
What is the python "with" statement designed for?

I came across the Python with statement for the first time today. I've been using Python lightly for several months …

python language-features with-statement
Oracle SQL insert into with With clause

I'm new to sql, so maybe it is a dumb question, but is there any possibility to use With clause …

sql oracle with-statement
Using python "with" statement with try-except block

Is this the right way to use the python "with" statement in combination with a try-except block?: try: with open("…

python finally with-statement try-catch except
Are there legitimate uses for JavaScript's "with" statement?

Alan Storm's comments in response to my answer regarding the with statement got me thinking. I've seldom found a reason …

javascript language-features with-statement
Create a "with" block on several context managers?

Suppose you have three objects you acquire via context manager, for instance A lock, a db connection and an ip …

python with-statement contextmanager
The VB.NET 'With' Statement - embrace or avoid?

At work, I'm frequently working on projects where numerous properties of certain objects have to be set during their construction …

vb.net with-statement