Thank you!

Wait, though.

How do I do this?

def differentnoofvars(*args,**kwargs):  ## By the way, is it **kwargs or
**kwds?
    print kwargs
    another(kwargs)

def another(**kwargs):
    for x,y in kwagrs.items():
        print "%s = %s" % (x,y)

a = ['a=2','f=3','t=[1,2,3]']  ## A list of kwargs that I want to send
individually to differentnoofvars
differentnoofvars(a)


> > Hey, could you give an example?
> > Thanks,
> > Jacob
> >
> > >
> > > apply() is deprecated; it has been replaced by 'extended
> > call syntax'.
> > Instead of
> > >    apply(fn, args, kwds)
> > > you can now write
> > >    fn(*args, **kwds)
> > >
> > > Kent
>
> Here is a quick example I came up with:
>
> >>> def spam(*args, **kwargs):
> ... print "Here are the args you supplied:"
> ... for item in args:
> ... print item
> ... print
> ... print "Here are the kwargs you supplied:"
> ... for key,value in kwargs.items():
> ... print key, '=', value
> ...
> >>> spam(1,'a','eggs',s=0, p=1, a=2, m=3)
> Here are the args you supplied:
> 1
> a
> eggs
>
> Here are the kwargs you supplied:
> a = 2
> p = 1
> s = 0
> m = 3
>
> In the case of the spam() function, 1, 'a', and 'eggs' are all put into
> the sequence args (not sure if it is a list or tuple).  The key/value
> pairs are bundled into the dictionary kwargs.  The arguments have to be
> given in the right order though:
>
> >>> spam(t=1, b=1, 'this', 'will', 'fail')
> Traceback (SyntaxError: non-keyword arg after keyword arg
>
> HTH!
>
> Christian
> http://www.dowski.com
>
>
>
>

_______________________________________________
Tutor maillist  -  [EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to