Nested Parameter Definitions

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Sun Feb 25 19:45:51 EST 2007


On Sun, 25 Feb 2007 11:06:03 -0800, Virgil Dupras wrote:

> On Feb 25, 1:00 pm, "Paddy" <paddy3... at googlemail.com> wrote:
>> I blogged on finding a new-to-me feature of Python, in that you are
>> allowed to nnest parameter definitions:
>>
>> >>> def x ((p0, p1), p2):
>>
>> ...     return p0,p1,p2

[snip]

> I didn't know about it either. Without the call example, I would have
> had a hard time to try to figure out what these extra brackets are
> for. For this reason, I think that an explicit unpack is more
> readable, and thus better.

And now that you do know, it is not hard to figure it out at all.

Nested parameters are no harder to figure out than *args or arg=value.
It's something that you learn, once, and then it is easy forever.

To my mind, def x ((p0, p1), p2) _is_ an explicit unpack. It just takes
place in the parameter definition, where you can see it even if the
source code is not available, not in the body of the function code, where
you may or may not even be able to find it.



-- 
Steven D'Aprano 




More information about the Python-list mailing list