Unpacking sequences and keywords in one function call
Gabriel Genellina
gagsl-py at yahoo.com.ar
Mon Nov 13 21:36:36 EST 2006
At Monday 13/11/2006 22:06, ram wrote:
>Stupid question #983098403:
>
>I can't seem to pass an unpacked sequence and keyword arguments to a
>function at the same time. What am I doing wrong?
>
>def f(*args, **kw):
> for a in args:
> print 'arg:', a
> for (k,v) in kw.iteritems():
> print k, '=', v
>
> >>> f(1,2)
>arg: 1
>arg: 2
>
> >>> f(*[1,2])
>arg: 1
>arg: 2
>
> >>> f(1,2, a=1)
>arg: 1
>arg: 2
>a = 1
>
> >>> f(*[1,2], a=1)
> File "<stdin>", line 1
> f(*[1,2], a=1)
> ^
> SyntaxError: invalid syntax
Reverse the order:
f(a=1, *[1,2])
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
More information about the Python-list
mailing list