[Python-ideas] parameter omit
Aaron Brady
castironpi at comcast.net
Fri May 11 04:11:40 CEST 2007
> -----Original Message-----
> From: Josiah Carlson [mailto:jcarlson at uci.edu]
> Sent: Thursday, May 10, 2007 8:04 PM
>
> "Aaron Brady" <castironpi at comcast.net> wrote:
> > Also, any follow-up on this? (I posted at top.)
>
> I don't like it. The current calling semantics are sufficient for the
> vast majority of cases. For those cases that are not covered by the
> current calling semantics, there is a PEP for allowing variations in
> optional arguments, keyword arguments, etc. I can't remember the number,
> but the PEP index has it.
>
> As for signaling "use the default", there is a standard method: omit the
> argument. If you want the argument to always be required to be a
> keyword argument, you can use...
>
> def foo(arg1, **kwargs):
> arg2 = kwargs.get('arg2', 1.2325)
> arg3 = kwargs.get('arg3', 'hello')
> ...
>
> - Josiah
I don't like it. Cobol is sufficient. Python is very cool.
> def foo(arg1, **kwargs):
> arg2 = kwargs.get('arg2', 1.2325)
> arg3 = kwargs.get('arg3', 'hello')
> ...
Library functions have many parameters, and huge if statements are hard to
read. My solution costs only a single built-in object, not even a keyword
or syntax modification. Your solution takes a three-line function
definition. Compare to mine:
def foo(arg1, argFoo=1.2325, argBree='hello'):
...
Specific and concise. Clearly better, by all measures I read.
More information about the Python-ideas
mailing list