In Python3 we can use multiple contexts in with statements. But is it possible to enter multiple contexts if they can't be constructed right away in the with statement? Is it possible to do something like this?
def files():
return open('a.txt', 'w'), open('b.txt', 'w')
with files():
pass
Or this:
files = open('a.txt', 'w'), open('b.txt', 'w')
with files:
pass
contextlib.ExitStackas that's my gut feeling but I'm still not sure what the use case is...with open(...), open().... Maybe saving context into variable is not nice, but pattern with a function should be fairy safe.