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

Terry Reedy tjreedy at udel.edu
Fri Aug 29 17:34:22 EDT 2003


"Michael Peuser" <mpeuser at web.de> wrote in message
news:bio39s$2ai$03$1 at news.t-online.com...
>
> "Terry Reedy" <tjreedy at udel.edu> schrieb im Newsbeitrag
> news:3dqcndZe5u2g4NKiXTWJiA at comcast.com...
>
> [...}
> >
> > 1. When you make a function call and use **whatever, it must be
the
> > last item in the argument list, just as in a function definition.
A
> > following comma is not allowed for either defs or calls.
>
> This in fact is not true. Funnily you can add *one* comma at the end
of any
> list-like construct.

For 2.2.1 and whatever version Andreas is running, **whatever is an
exception and CANNOT be followed by a comma in either def or call,
just as I said.  I tested before writing.   (Did you?  Can you test
below on 2.3?)

>>> def f(**d):
...   for i,v in d.items(): print i, v
...
>>> b={'one':1, 'two':2}
>>> f(**b)
two 2
one 1
>>> f(**b,)
  File "<stdin>", line 1
    f(**b,)
         ^
SyntaxError: invalid syntax

>>> def f2(**d,): pass
  File "<stdin>", line 1
    def f2(**d,): pass
              ^
SyntaxError: invalid syntax

# On the original fixed-pitch font screen, both arrows point at
offending comma.

Can someone verify this for 2.3?  If so, there is a bug in either doc
or interpreter.

Terry J. Reedy






More information about the Python-list mailing list