Is there a way to begin a block of code with a with statement, but conditionally?
Something like:
if needs_with(): with get_stuff() as gs: # do
A third-party option to achieve exactly this: https://pypi.python.org/pypi/conditional
from conditional import conditional with conditional(needs_with(), get_stuff()): # do stuff