Argument Precedence (possible bug?)

Fredrik Lundh fredrik at pythonware.com
Sun Mar 5 08:09:47 EST 2006


"vbgunz" wrote:

> I am just learning Python and have come across something I feel might
> be a bug. Please enlightenment me... The following code presents a
> challenge. How in the world do you provide an argument for *arg4?
>
> ## ============================================================
> def argPrecedence(par1, par2=0, par3=0, *par4, **par5):
>     print 'par1 =', par1, ' # positional argument'
>     print 'par2 =', par2, ' # keyword argument'
>     print 'par3 =', par3, ' # keyword argument'
>     print 'par4 =', par4, ' # argument converted to tuple'
>     print 'par5 =', par5, ' # argument converted to dictionary'
>
> argPrecedence('arg1', arg3='arg3', arg2='arg2', arg5='arg5')
>
> # argPrecedence Results:
> par1 = arg1  # positional argument
> par2 = arg2  # keyword argument
> par3 = arg3  # keyword argument
> par4 = ()  # argument converted to tuple
> par5 = {'arg5': 'arg5'}  # argument converted to dictionary
> ## ============================================================
>
> The code above is verbose with comments because I am just learning
> Python and am creating my own examples and reference materials... Can
> you solve the problem? If so, can you share the solution? If not, is
> this a bug, limitation or is it a feature?

not sure what you think the bug is, but I suspect that you've completely
missed the point of what * and ** do, and how they're used in real code.

</F>






More information about the Python-list mailing list