[Zope] Something missing in Python Methods

Evan Simpson evan@4-am.com
Tue, 2 Jan 2001 09:53:18 -0500


From: Curtis Maloney <curtis@cardgate.net>
> What I want to know is, why can't Python Methods refer to anything not
> explicitly passed to them?  I don't want to have to make everything that
> invokes the method have to know to pass it half a dozen objects.
>
> Isn't the idea of a method to be executed in the namespace of it's parent?
I
> want my method to be able to access objects in it's own folder...

Yep.  You just need to make the first parameter of your method 'self', and
not have any parameters with default values.  For example, method plusX::

  <params>self, x</params>
  return len(self.objectIds()) + x

...can be called like 'folder.plusX(3)'.  You can also acquire objects that
your method needs from 'self'.

Cheers,

Evan @ digicool & 4-am