"with" statement in python, why must the "as" section be a single object

Viewed 502

With Python one can say:

a,b,c=something_that_returns_a_3_tuple()

But a with statement like:

class thing(object):
    def __enter__(self):
        return (1,2,3)

    def __exit__(self,a,b,c):
        pass

with thing() as a,b,c:
    print a
    print b 
    print c

will not work work

One must have:

class thing(object):
    def __enter__(self):
        return (1,2,3)

    def __exit__(self,a,b,c):
        pass

with thing() as (a,b,c):
    print a
    print b 
    print c

I can't see a practical problem with allowing the first form, by this I mean implementation or logical, the parser shouldn't have a problem with commas (it wont be ambiguous) and I see no logical reason why not.

http://docs.python.org/release/2.5/whatsnew/pep-343.html

and http://www.python.org/dev/peps/pep-0343/ suggests this is just syntatic sugar

1 Answers
Related