Parameter passing in python

D-Man dsh8290 at rit.edu
Thu May 31 10:56:38 EDT 2001


On Thu, May 31, 2001 at 04:47:06PM +0200, Laura Creighton wrote:
| (posted by me, but this is from all of us here .... )
| 
| ---------------------------------------
| This is what I have to do in my code when inheriting widgets:
| 
| import Pmw
| 
| class MyButtonBox(Pmw.ButtonBox)
|     def __init__(self, parent, **kw):
|        ...
|         apply(Pmw.ButtonBox.__init__, (self, parent), kw)
| 
| Why am I required to do apply to be able to pass the keyword list?

What version of python are you using?

| Some model of Pmw.ButtonBox.__init__(self, args) would be
| more readable.

If you have Python >= 2.0 then you can use an asterisk like pointer
dereferencing :


Pmw.ButtonBox.__init__( self, parent , **kw )

The issue is :
    o do you want to pass the dict as a single object to be bound to a
      single formal argument

    o or do you want the dict to represent all the actual arguments
      that should be expanded to bind each element to the
      corresponding formal argument?

Prior to 2.0 the 'apply' function was the only way to achieve the
latter.  Starting with 2.0 the "pointer dereferencing" notation was
added to specify the latter.

-D





More information about the Python-list mailing list