molasses said:
I don't mind the naked star and will be happy if thats what we end up with.
Though how about using *None?
I think that makes the intention of the function clearer.
eg.
def compare(a, b, *None, key=None):
Which to me reads as "no further positional arguments".
Or alternatively:
def compare(a, b, *0, key=None):
-- Mark
Argh!
Sorry, but this syntax seems to me a perlish hackaround. Although the
star is clearly beautifull and veeeery pythonic
One can easily envision a function
which takes a variable number of arguments, but also takes one
or more 'options' in the form of keyword arguments. Currently,
the only way to do this is to define both a varargs argument,
and a 'keywords' argument (**kwargs), and then manually extract
the desired keywords from the dictionary.
The current solution is fine and not very troublesome. But if you want
to drop a named dict just replace it by an unnamed one ( unless you
think this will seduce people to use devilish, horrible lambda ... ).
Suggestions:
def compare(a, b, *args, **kwd): # the classics
def compare(a, b, *args, {"key":None}): # pass keywords in unnamed
dict
def compare(a, b, *args, {key=None}): # alternative syntax
def compare(a, b, *args, **kwd={...,"key":None}): # having the
cake and eating it
Regards,
Kay