Specifiying keyword arguments with *args and **kws
<p>I've found a behavior in Python that has baffled and irritated me and I was wondering what I got wrong...</p>

<p>I have a function which should take an arbitrary number of arguments and keywords, but in addition should have some default-valued keywords that comprise it's actual interface:</p>

<pre><code>def foo(my_keyword0 = None, my_keyword1 = 'default', *args, **kws):
    for argument in args:
        print argument
</code></pre>

<p>The problem is that if I try calling <code>foo(1, 2, 3)</code> I'll only get the printout for 3 and the values 1 and 2 will override my keyword arguments.</p>

<p>On the other hand if I try moving my keywords after the <code>*args</code> or after the <code>**kws</code> it will cause a syntax error. The only solution I found to the problem was to extract the keyword arguments from <code>**kws</code> and setting default values to them:</p>

<pre><code>def foo(*args, **kws):
    my_keyword0 = None if 'my_keyword0' not in kws else kws.pop('my_keyword0')
    my_keyword0 = 'default' if 'my_keyword1' not in kws else kws.pop('my_keyword1')
    for argument in args:
        print argument
</code></pre>

<p>This is horrible both because it forces me to add pointless code and because the function signature becomes harder to understand - you have to actually read the functions code rather than just look at its interface.</p>

<p>What am I missing? isn't there some better way to do this?</p>
