function with variable number of arguments

Joachim Kaeber kaeber at gmd.de
Thu Jun 24 08:51:13 CEST 1999


Hi,

l.a.apiolaza at massey.ac.nz wrote:

> I want to write a function that takes a bunch of  'n' matrices (defined
> using array from NumPy) and processes them further. Question: how do I
> write a function with a variable number 'n' of arguments and then get
> the number of arguments? I think I can put all the matrices together in
> a list and then pass the list as argument, but is there another more
> efficient/elegant way of doing it?

What about:

>>> def f(*args):
...     for l in args:
...             print l
...
>>> f([1,2,3], [4,5,6])
[1, 2, 3]
[4, 5, 6]

-- 
Joachim Kaeber (kaeber at gmd.de) (http://mats.gmd.de/~kaeber)
GMD - Forschungszentrum Informationstechnik GmbH
    - German National Research Center for Information Technology
Schloss Birlinghoven                    email: kaeber at gmd.de
D-53757 Sankt Augustin 1, Germany       phone: (+49 2241) 14-2546




More information about the Python-list mailing list