method (a, b = '', *c, **d): gets a syntax error?

Piet van Oostrum piet at cs.uu.nl
Mon Sep 1 10:31:06 EDT 2003


>>>>> Andreas Neudecker <a.neudecker at uni-bonn.de> (AN) wrote:

AN> Still it puzzles me that in one case it is okay in the other one not. Seems
AN> unlogical to me. Can anyone enlighten me to why this is so?

It is quite logical. The idea behind the optional comma after the last
parameter is such that it would be easy to change your function to include
additional parameters. When you put each parameter on a separate line (as
you did in your examples) , you just have to add a single line with the new
parameter and it doesn't matter whether the new parameter comes in as the
last one or at any other place. If you leave out the final comma, and the
new parameter is the last one, you would have to add the comma to the
previous line, which can easily be forgotten.

However, when you have  **kwargs it must be last, so there is no need to
put an additional comma. In fact it would be confusing as it would suggest
that you can add additional parameters after it.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl




More information about the Python-list mailing list