Re: How to do *args, **kwargs properly

2005-10-11 Thread Max M
Lasse Vågsæther Karlsen wrote: > Max M wrote: > So what you're saying is that instead of: > > def fn(*values, **options): > > I should use: > > def fn(values, cmp=cmp): > > in this specific case? > > and then instead of: > > fn(1, 2, 3, cmp=...) > > this: > > fn([1, 2, 3], cmp=...) Precis

Re: How to do *args, **kwargs properly

2005-10-11 Thread Lasse Vågsæther Karlsen
George Sakkis wrote: > "Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: >>I think I'll re-write to use a list instead > > > Actually in most cases you don't need to assume it's a list; any > iterable is usually good enough. You can always turn it into a list (or > a tuple or a set or..) in t

Re: How to do *args, **kwargs properly

2005-10-11 Thread George Sakkis
"Lasse Vågsæther Karlsen" <[EMAIL PROTECTED]> wrote: > So what you're saying is that instead of: > > def fn(*values, **options): > > I should use: > > def fn(values, cmp=cmp): > > in this specific case? > > and then instead of: > > fn(1, 2, 3, cmp=...) > > this: > > fn([1, 2, 3], cmp=...) > > > >

Re: How to do *args, **kwargs properly

2005-10-11 Thread Lasse Vågsæther Karlsen
Max M wrote: > Lasse Vågsæther Karlsen wrote: > >> I must be missing something but what is the proper way to do a >> function using such arguments ? > > >> - ability to take an unspecified number of "positional arguments" > > > You should probably pass a sequence to the method instead. You ca

Re: How to do *args, **kwargs properly

2005-10-11 Thread Max M
Lasse Vågsæther Karlsen wrote: > I must be missing something but what is the proper way to do a function > using such arguments ? > - ability to take an unspecified number of "positional arguments" You should probably pass a sequence to the method instead. You can do it the other way, but it's

Re: How to do *args, **kwargs properly

2005-10-11 Thread Alex Martelli
Lasse Vågsæther Karlsen <[EMAIL PROTECTED]> wrote: ... > fn(1, 2, 3) > fn(1, 2, 3, cmp=lambda x, y: y-x) > fn(1, 2, 3, cpm=lambda x, y: y-x) # TypeError on this I assume these are your specs. > or is the "proper python" way simply this: > > def fn(*values, **options): > if "cmp" in optio

Re: How to do *args, **kwargs properly

2005-10-11 Thread Paul Rubin
Lasse Vågsæther Karlsen <[EMAIL PROTECTED]> writes: > or is the "proper python" way simply this: > > def fn(*values, **options): > if "cmp" in options: comparison = options["cmp"] > else: comparison = cmp > # rest of function here > > and thus ignoring the wrong parameter names? I

How to do *args, **kwargs properly

2005-10-11 Thread Lasse Vågsæther Karlsen
I must be missing something but what is the proper way to do a function using such arguments ? Specifically I'm looking for: - ability to take an unspecified number of "positional arguments" - ability to take optional named arguments that follows the first arguments - raise appropriate errors if