Argument Precedence (possible bug?)

vbgunz vbgunz at gmail.com
Sun Mar 5 07:40:22 EST 2006


Hello all,

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', par3='arg3', par2='arg2', par5='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?

Thank you for your time on this one!

PS. I could be far off with this codes purpose; to try and create an
example that will house all the different possible parameters
(positional, keyword, * and **) in one single def statement.

--  
Best Regards
Victor B. Gonzalez




More information about the Python-list mailing list