Restrict 'as VAR' to VAR being a single variable or a parenthesized

series of variables.  This keeps the door open for a future extension
with multiple as-clauses.
This commit is contained in:
Guido van Rossum 2005-06-11 05:14:20 +00:00
parent d75a3b0145
commit a61abd2828
1 changed files with 7 additions and 3 deletions

View File

@ -207,8 +207,12 @@ Specification: The 'with' Statement
BLOCK
Here, 'with' and 'as' are new keywords; EXPR is an arbitrary
expression (but not an expression-list) and VAR is an arbitrary
assignment target (which may be a comma-separated list).
expression (but not an expression-list) and VAR is a single
assignment target. It can *not* be a comma-separated sequence of
variables, but it *can* be a *parenthesized* comma-separated
sequence of variables. (This restriction makes a future extension
possible of the syntax to have multiple comma-separated resources,
each with its own optional as-clause.)
The "as VAR" part is optional.
@ -573,7 +577,7 @@ Examples
Used as follows:
with opening_w_error("/etc/passwd", "a") as f, err:
with opening_w_error("/etc/passwd", "a") as (f, err):
if err:
print "IOError:", err
else: