[Python-talk] Can I do this?

Lloyd Kvam python at venix.com
Wed Feb 3 18:04:09 EST 2010


On Wed, 2010-02-03 at 17:07 -0500, bruce.labitt at autoliv.com wrote:


> funclist = funcs[:p]    # just select the first p functions of func
> arglist  = args1[:p]    # likewise the first p args to feed to the 
> corresponding function
(Not needed)

> for bb, func, argn in zip( range(p), funcs, argsl):
range(p) terminates the zip if p is less than the len of funcs and argsl

>         idx = bb
leave idx out of the args

>         WW[bb,:] = func( *argn )
	     ^^^^ I assume that syntax works with your complex array
WW[bb,:] = func( bb, *argn)
add the loop index directly into the function call


> Inside of args1[i] are tuples of parameters. 
> 
> For example:
>         args1[0] = ( idx, t, snr )
>         args1[3] = ( idx, t, snr, omega, rho )
> 
> Do I need to update arglist for every iteration of the loop?  Then I 
> should remove arglist from the zip, right?

Let me try to restate the issue.  

The argument tuples contain the loop index along with some other values
that are constant during the loop.  So you need to add the loop index to
the argument tuple for each function call in the loop.

If the loop index is the first argument in the call parameters then you
can write the call as:
	func( loop_index, *argsl[loop_index])

Just remove idx from the argument tuples.

> 
> More like
> 
> for bb, func in zip( range(p), funclist ):

Note that range(p) will terminate the zip at p items even if the funcs
and args are longer.

>         args1 = [( bb, t, snr), ..., (bb, t, snr, omega, rho), ... ]\
This is not needed because you fix the func call

>         WW[bb,:] = func( *args1[bb] )
> 
> ???  Seems kind of silly just to update only the index...  An easier
> way 
> possible?
> 


-- 
Lloyd Kvam
Venix Corp
DLSLUG/GNHLUG library
http://dlslug.org/library.html
http://www.librarything.com/catalog/dlslug
http://www.librarything.com/rsshtml/recent/dlslug
http://www.librarything.com/rss/recent/dlslug



More information about the Python-talk mailing list