Why python doesn't use syntax like function(,,x) for default parameters?

Juho Schultz juho.schultz at helsinki.fi
Fri Mar 10 09:30:05 EST 2006


Antoon Pardon wrote:
> Op 2006-03-10, Roy Smith schreef <roy at panix.com>:
> 
>>"Dmitry Anikin" <anikin#remove_this#@vstu.ru> wrote:
>>
>>>There are often situations when a function has independent
>>>parameters, all having reasonable defaults, and I want to
>>>provide just several of them. In fact, I can do it using
>>>keyword parameters, but it's rather long and you have to
>>>remember/lookup names of parameters.
>>
>>Specifying the names of the keyword parameters costs you a little typing 
>>once, but saves everybody (including yourself) a lot of grief later when 
>>you're trying to figure out what the heck your code does 6 months later.
> 
> 
> Could you explain what is so hard in figuring out:
> 
>   func(,,4)
> 

Your func has only three parameters, and only one non-default.
I think "all have reasonable defaults, I want to provide several"
means you might end up with bugs like this.

func(,,,1.2e-3,7.6e18,3.124576,3567.0,)
func(,,1.24e3,1,21.26e4,,,1220,57,35,0) # bug
TypeError: func() takes exactly 8 arguments (9 given)

Now what are the correct arguments?
1220.57, 35,    and 0
1220,    57.35, and 0
1220,    57,    and 35.0

With keywords parameters, this is easy to answer.

func(y=1.2e-3, z=7.6e18, i=3.124576, j=3567.0)
func(x=1.24e3, y=1, z=21.26e4, j=1220, k=57,35, w=0) # bug

SyntaxError: non-keyword arg after keyword arg.



More information about the Python-list mailing list