On Fri, 10 Mar 2006 12:06:57 +0300, Dmitry Anikin wrote: > I mean, it's very convenient when default parameters > can be in any position, like > def a_func(x = 2, y = 1, z): > ... > (that defaults must go last is really a C++ quirk which > is needed for overload resolution, isn't it?)
I'm confused... it looks to me like the defaults are *first*, not last, in the above definition. We write from left to write in English, so normal convention in English is that first -> last, not last <- first. > and when calling, just omit parameter when you want to > use defaults: > a_func(, , 3) Can you do this? another_func(,,,4,,,,) That looks like bug-city to me. (Did I mean 4 to go in the fourth position or fifth?) In any case, given the way Python defaults work, the commas are superfluous. There is no ambiguity: def f(w, x, y=1, z=1): pass Positional arguments without defaults *must* go first, and must be supplied: f(5, 6) => w=5, x=6, y=1, z=1 Commas would be pointless: f(5, 6, , ) isn't needed, because the first and second arguments are already assigned to the w and x arguments before the first empty comma is spotted. You can't do this: f(, , 5, 6) => w,x = default, y=5, z=6 because w and x don't have defaults. > 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. And you think it is easier to remember the position of parameters rather than their names? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list