os.path.join and lists

Andrew Dalke dalke at dalkescientific.com
Wed Oct 17 21:29:28 EDT 2001


Uwe Schmitt:
>hi, whats the meaning of "*baz" ?? i've never seen this before....

It's new starting with Python 2.0

Older Pythons let you do

def f(*args, **kwargs):
  print args, kwargs

>>> f(1, "this", x = 1.0, y = 9)
(1, 'this') {'x': 1.0, 'y': 9}

But there was no easy way to do the opposite.

args = (1, 'this')
kwargs = {'x": 1.0, 'y': 9}
apply(f, args, kwargs)

With Python 2.0, this is simplified to

f(*args, **kwargs)

Eg:

>>> def g(x, y):
...     print x + y
...
>>> g(**{"x": 8, "y": -5})
3
>>>

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list