Functions does not accept keyword arguments if an argument list specified

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Sun Feb 16 21:48:59 EST 2003


Létezõ wrote:

 >>>>fn(*al,a=3,b=4)
 >>>>
 >   File "<stdin>", line 1
 >     fn(*al,a=3,b=4)
 >            ^
 > SyntaxError: invalid syntax

 >
 > Python should
 > allow applying an argument list while passing real keyword arguments.

It does, but the * and ** arguments have to go *after* any
positional or keyword arguments:

   >>> fn(a=3,b=4,*al)
   args=(1, 2), kw={'a': 3, 'b': 4}

It could be argued that this is somewhat unintuitive,
but that's the way the grammar is defined, perhaps
for consistency with the syntax for function definitions
(where * and ** also have to appear last).

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list