On 09/08/2012 01:41, bruceg113355 [at] gmail wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce >

On 08/08/2012 08:41 PM, bruceg113355 [at] gmail wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce If a function is expecting exactly 8 arguments, and z is a list of length 8, you can call the function like:

testData(*z)

if z is longer, then you'd need something like (untested) testData(*z[:8])

The * basically turns a list into separate arguments, and these are then applied to the formal parameters.

bruceg113355 [at] gmail wrote: > Is there a way in Python to pass arguments without listing each argument? > For example, my program does the following: > > testData (z[0], z[1], z[2], z[3], z[4], z[5], z[6], z[7]) > > Is there a clever way to pass arguments in a single statement knowing that each argument is a sequential index from a list? > I cannot change the function definition. > > Thanks, > Bruce > testData(*z)

or better (imo)

testData(z) and make testData handle a list (8 parameters, that's a lot of parameters).

True but it is still worth highlighting that the function definition may not be ideal depending on the requirements of the function. some people read these threads to learn general concepts & not to find answers to a single explicit case.