* in Python

placid Bulkan at gmail.com
Sat Jun 24 03:18:15 EDT 2006


Bruno Desthuilliers wrote:
> placid wrote:
> > Bruno Desthuilliers wrote:
> >
> (snip)
> >>Why don't you try by yourself in the Python shell ? One of the nice
> >>things with Python is that it's quite easy to explore and experiment.
> >
> >
> > i did try it in a  Python shell after i learnt what it was. Like i said
> > *args will be a list, but when i try **args with the following code it
> > doesnt work
>
> "doesn't work" is the most useless description of a problem.
>
> > def test(**args):
> >     keys = args.keys()
> >     for key in keys:
> >         print key+"="+args(key)
>
> you want args[key], not args(key)
>
> And you forget to tell how you called this code and what you got.

Too much world cup means sleepless nights down here in Australia or i
would have seen the error with args(key) which suppose to be args[key]
!

>
> FWIW:
> Python 2.4.3 (#1, Jun  3 2006, 17:26:11)
> [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def test(**kw):
> ...     for item in kw.items():
> ...             print "%s : %s" % item
> ...
> >>> test()
> >>> test(parrot="dead", walk="silly", nose="big")
> nose : big
> parrot : dead
> walk : silly
> >>> test(**{'answer':42})
> answer : 42
> >>>

Thanks for that now i know what * means.




More information about the Python-list mailing list