1 Oct
2016
1 Oct
'16
3:45 p.m.
On Sun, Oct 2, 2016 at 5:07 AM, Neil Girdhar
I suggest a more compact notation:
with cm_function() as cm if condition: suite()
The simplest way would be to make a conditional version of the context manager. @contextlib.contextmanager def maybe_cm(state): if state: with cm_function() as cm: yield cm else: yield None I believe that'll work. ChrisA