[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

WANTED: A good name for the pair (args, kwargs

Jonathan Fine

3/4/2010 12:30:00 PM

Hi

We can call a function fn using
val = fn(*args, **kwargs)

I'm looking for a good name for the pair (args, kwargs). Any suggestions?

Here's my use case:
def doit(fn , wibble, expect):
args, kwargs = wibble
actual = fn(*args, **kwargs)
if actual != expect:
# Something has gone wrong.
pass

This is part of a test runner.

For now I'll use argpair, but if anyone has a better idea, I'll use it.

--
Jonathan
5 Answers

Tim Chase

3/4/2010 12:50:00 PM

0

Jonathan Fine wrote:
> We can call a function fn using
> val = fn(*args, **kwargs)
>
> I'm looking for a good name for the pair (args, kwargs). Any suggestions?
>
> For now I'll use argpair, but if anyone has a better idea, I'll use it.

In the legacy of C and Java (okay, that doesn't carry _much_
weight with me), I'd go with "varargs" to refer to the pair of
(args, kwargs)

-tkc



Paul Rubin

3/4/2010 1:38:00 PM

0

Jonathan Fine <J.Fine@open.ac.uk> writes:
> I'm looking for a good name for the pair (args, kwargs). Any suggestions?
>
> Here's my use case:
> def doit(fn , wibble, expect):
> args, kwargs = wibble
> actual = fn(*args, **kwargs)

I think this may have been broken in 3.x, but in 2.6 the compiler will
unpack directly if you put a tuple structure in the arg list:

def doit(fn, (args, kwargs), expect):
actual = fn(*args, **kwargs)

Otherwise I'd just say "all_args" or some such. Or just "args" which
you unpack into "pos_args" (positional args) and "kw_args".

Steve Holden

3/4/2010 6:15:00 PM

0

Jonathan Fine wrote:
> Hi
>
> We can call a function fn using
> val = fn(*args, **kwargs)
>
> I'm looking for a good name for the pair (args, kwargs). Any suggestions?
>
> Here's my use case:
> def doit(fn , wibble, expect):
> args, kwargs = wibble
> actual = fn(*args, **kwargs)
> if actual != expect:
> # Something has gone wrong.
> pass
>
> This is part of a test runner.
>
> For now I'll use argpair, but if anyone has a better idea, I'll use it.
>
Not being able to find any existing names I called *args the
sequence-parameter and **kwarg the dict-parameter.

For your use, though, you might choose something like the "generic
parameter pair).

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us....
Holden Web LLC http://www.hold...
UPCOMING EVENTS: http://holdenweb.event...

aahz

3/5/2010 6:01:00 AM

0

In article <mailman.284.1267707023.23598.python-list@python.org>,
Tim Chase <python.list@tim.thechases.com> wrote:
>Jonathan Fine wrote:
>>
>> We can call a function fn using
>> val = fn(*args, **kwargs)
>>
>> I'm looking for a good name for the pair (args, kwargs). Any suggestions?
>>
>> For now I'll use argpair, but if anyone has a better idea, I'll use it.
>
>In the legacy of C and Java (okay, that doesn't carry _much_ weight
>with me), I'd go with "varargs" to refer to the pair of (args, kwargs)

Ditto
--
Aahz (aahz@pythoncraft.com) <*> http://www.python...

"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer

Jonathan Fine

3/5/2010 3:20:00 PM

0

Jonathan Fine wrote:
> Hi
>
> We can call a function fn using
> val = fn(*args, **kwargs)
>
> I'm looking for a good name for the pair (args, kwargs). Any suggestions?
>
> Here's my use case:
> def doit(fn , wibble, expect):
> args, kwargs = wibble
> actual = fn(*args, **kwargs)
> if actual != expect:
> # Something has gone wrong.
> pass
>
> This is part of a test runner.
>
> For now I'll use argpair, but if anyone has a better idea, I'll use it.

Thank you, Tim, Paul, Steve and Aahz for your suggestions.

I'm now preferring:

def test_apply(object, argv, valv):

args, kwargs = argv
expect, exceptions = valv

# Inside try: except:
actual = object(*args, **kwargs)

# Check against expect, exceptions.

best regards


Jonathan