In python, I can define a function as follows:
def func(kw1=None,kw2=None,**kwargs): ...
In this case, I can call func like:
func(kw1=3,kw2=4,who_knows_if_this_will_be_used=7,more_kwargs=Ellipsis)
I can also define the function as:
def func(arg1,arg2,*args): ...
which can be called
func(3,4,additional,arguments,go,here,Ellipsis)
Finally, I can combine the two forms
def func(arg1,arg2,*args,**kwargs): ...
But what does not work causes:
func(arg1,arg2,*args,kw1=None,kw2=None,**kwargs):
My initial thought was that it was probably because the function
def func(arg1,arg2,*args,kw1=None): ...
can be called
func(1,2,3)
Thus, this will lead to some ambiguity as to whether 3 should be packed in args or kwargs. However, with python 3, you can only specify keyword arguments:
def func(a,b,*,kw=None):
With this, there seems to be no syntactic ambiguity with:
def func(a,b,*args,*,kw1=None,**kwargs): ...
However, this still causes a syntax error (verified with Python3.2). Is there a reason for this that I am missing? And is there any way to get the behavior described above (having arguments with default arguments). I know that I can simulate this behavior by manipulating the kwargs dictionary inside a function.