Nov. 15, 2019
10:35 p.m.
On 16/11/19 4:30 am, Joao S. O. Bueno wrote:
Just add __enter__ and __exit__ to tuples themselves!
That wouldn't give the same result, though. E.g. if you're using open(), a failure to open a later file in the list should trigger the __exit__ of earlier ones. But using a tuple, all the files have been opened before the with statement gets a look in. To get the right semantics, evaluation of the context manager expressions needs to be under the control of the with-statement. -- Greg