[Python-Dev] "as" mania

Paul Moore p.f.moore at gmail.com
Tue Mar 7 21:49:27 CET 2006


On 3/7/06, Andrew Koenig <ark at acm.org> wrote:
> As it turns out, Python has similar ways of decomposing data structures:
>
>         (x, y) = foo
>
> or
>
>         def bar((x, y)):
>                 # etc.
>
> and I have sometimes wished I could write
>
>         z as (x, y) = foo
>
> or
>
>         def bar(z as (x, y)):
>                 # etc.
>
> However, it's not real high on my list of priorities, and I suspect that
> many Pythonists consider these usages to be a frill anyway.

For the assignment case, you can do this:

>>> foo = (1,2)
>>> (x,y) = z = foo
>>> x
1
>>> y
2
>>> z
(1, 2)
>>>

Function arguments are not covered by this trick, but

    def bar(z):
        (x,y) = z

probably isn't too much overhead...

(Or did I miss your point?)

Paul.


More information about the Python-Dev mailing list