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

Terry Reedy tjreedy at udel.edu
Fri Aug 29 12:20:11 EDT 2003


"Andreas Neudecker" <a.neudecker at uni-bonn.de> wrote in message
news:3F4F644D.2060003 at uni-bonn.de...
> class WhatsUp:
>      __call__ (
>             self,
>             var1,
>             var2 = '',
>             *moreVars,
>             **moreNamedVars,
>          ):
>          pass
>
>
> I always get an error for the **moreNamedVars, line where the '^'
points
> at the comma at the end (or, if I remove the comma, it points at the
> colon). ...What is wrong?

Generaly, when reporting 'I got an error', you should copy the actual
error message.  In this case, I presume you got 'SyntaxError: invalid
syntax' for each of your two syntax errors.

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.  So when you
add 'def' to correct your actual error, you also need to omit the
comma.

2. The colon suffix is required for defs but forbidden for calls.
With the comma present, the parser never got far enough to this.
Unlike most batch compilers, the CPython parser quits at the first
error it sees.  So when you correct one error and resubmit, you may
expose another further in your code.

Welcom to Python.  Enjoy.

Terry J. Reedy






More information about the Python-list mailing list