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

Andreas Neudecker a.neudecker at uni-bonn.de
Fri Aug 29 14:18:06 EDT 2003


Sorry, have to correct myself on the comma topic:


class WhatsUp:
     # No comma at the end of the list. This works fine.
     def method1 (
             self,
             var1,
             var2 = '',
             *more,
             **moreNamed
         ):
         print "This works fine."

     # This also works fine, even with the comma at the end.
     def method2 (
             self,
             var1,
             var2 = '',
             var3 = '', # <- THIS COMMA IS FINE.
         ):
         print "This works fine."

     # This will raise a Syntax error because of the comma.
     def method3 (
	        self,
             var1,
             var2 = '',
             *more,
             **moreNamed, # <- THIS COMMA IS NOT ALLOWED.
             ):
         print "The comma at the end of the parameter list will \
             raise a syntax error."


So to me it looks like it makes a difference whether the list contains a 
variable parameter list or not. I use the version as in method2 often 
for reasons stated in my previous posting.

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

Thanks to all of you who bothered to point me to my stupid error of 
forgetting the 'def' and discussing with me the comma problem.


Kind regards


Andreas






More information about the Python-list mailing list