This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Support for multiple handlers for the "with" statement
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Stavros, gvanrossum
Priority: low Keywords:

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:28adminsetgithub: 45776
2007-11-13 18:33:15gvanrossumsetstatus: open -> closed
resolution: wont fix
messages: + msg57464
nosy: + gvanrossum
2007-11-13 14:23:23christian.heimessetpriority: low
type: behavior -> enhancement
components: + Interpreter Core, - None
versions: + Python 2.6
2007-11-13 12:36:05Stavrossetmessages: + msg57447
2007-11-13 12:18:00Stavroscreate