apply problems

Joal Heagney s713221 at student.gu.edu.au
Sat Jul 14 02:50:50 EDT 2001


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: _____           _____
   /\ _     __   __ _    |     | _  ___  |
  /__\|\  ||   ||__ |\  || |___|/_\|___] |
 /    \ \_||__ ||___| \_|! |   |   \   \ !



More information about the Python-list mailing list