apply problems

Curtis Jensen cjensen at bioeng.ucsd.edu
Mon Jul 16 14:09:59 EDT 2001


Joal Heagney wrote:
> 
> Curtis Jensen wrote:
> 
> > I thought about that.  But in the test examples below, you can see that
> > you'll that you don't have to pass "self" with apply.  In fact if you
> > do, you'll end up with too many parameters.  Also, symanticly, I think
> > "apply( self.ren.Elements, (self, cmd[1]), additional_kwds )" will only
> > pass two arguments "self" and "cmd[1]" as apposed to sending "self" and
> > all the items in "cmd[1]" as individual argument.  You'd need to put
> > "self" at the beginning of cmd[1], or make a new tuple to pass in.  But
> > I know what you mean.
> 
> If you need to add a self argument to a list of arguments, (Usually if
> you're calling an unbound class method) the typical method is as
> follows:
> 
> apply( self.ren.Elements, (self,)+cmd, additional_kwds )
> 
> Of course this is assuming that cmd is a tuple. If it's a list you need
> to do the following:
> 
> apply( self.ren.Elements, (self,)+tuple(cmd), additional_kwds
> 
> > In any case, my problem went away.  I'm not exactly sure why.  It
> > probably had to do with unsafe dynamic binding or something like that.
> > :)
> 
> Would you be able to show us what cmd and additional_kwds typically look
> like?
> --
>       Joal Heagney is: _____           _____
>    /\ _     __   __ _    |     | _  ___  |
>   /__\|\  ||   ||__ |\  || |___|/_\|___] |
>  /    \ \_||__ ||___| \_|! |   |   \   \ !


cmd is always a list.  The size and element types varies greatly, but it
is usualy made of integers, floats, and lists.  ie:
cmd[1] = [0, 0, 3, 3, 0.0, [0]]

additional_kwds is always a dictionary with instances of classes as it's
values. These classes are a bit complex (lots of data members,
functions, and inheritance).  ie:
additional_kwds = {'prob': None, 'datum': None, 'elements': 
<cont_classes.Elements.Elements instance at 103849c0>, 'nodes': 
<cont_classes.Nodes.Nodes instance at 10384750>}
additional_kwds is always 


-- 
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451



More information about the Python-list mailing list