* in Python

Bruno Desthuilliers onurb at xiludom.gro
Fri Jun 23 16:50:01 CEST 2006

placid wrote:
> Bruno Desthuilliers wrote:
>>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.

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

bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"

More information about the Python-list mailing list