PEP 3102 for review and comment

M

molasses

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
 
K

Kay Schluehr

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 ;)
From the PEP:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top