Issue 1435: Support for multiple handlers for the "with" statement (original) (raw)

Issue1435

Created on 2007-11-13 12:18 by Stavros, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg57446 - (view) Author: Stavros Korokithakis (Stavros) Date: 2007-11-13 12:17
Currently, the new "with" statement does not support multiple handlers. For example, to open two files for input/output you would have to do: with open("filein") as input: with open("fileout") as output: #Do stuff pass This adds unnecessary complexity, and would be unwieldy with multiple code blocks. Would something like the following be feasible? with open("filein") as input, open("fileout") as output: # Do stuff pass This syntax is fully backwards-compatible, so there shouldn't be any problem there.
msg57447 - (view) Author: Stavros Korokithakis (Stavros) Date: 2007-11-13 12:36
What this syntax does is similar to the nested context manager in case 12 of PEP343, but with cleaner syntax.
msg57464 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-13 18:33
I don't think the added syntactic complexity is worth the relatively rare use case, especially since there's already an implementation of nested() in the contextlib library.
History
Date User Action Args
2022-04-11 14:56:28 admin set github: 45776
2007-11-13 18:33:15 gvanrossum set status: open -> closedresolution: wont fixmessages: + nosy: + gvanrossum
2007-11-13 14:23:23 christian.heimes set priority: lowtype: behavior -> enhancementcomponents: + Interpreter Core, - Noneversions: + Python 2.6
2007-11-13 12:36:05 Stavros set messages: +
2007-11-13 12🔞00 Stavros create