[Zope] problem with acquisition

Terry Hancock hancock at anansispaceworks.com
Wed Jun 23 10:46:37 EDT 2004


On Friday 18 June 2004 09:27 am, John Hunter wrote:
> I have a zope containment hierarchy
>   base/somefolder/myobj
>   base/other
> 
> I would like to acquire the 'other' folder from a myobj instance using
> the python API.  Ie, I have a class method in which I need to be able
> to do
> 
>   def somemethod(self, someinstance):
>        otherFolder = acquisition_magic(someinstance, 'other')

So "somemethod" is a class-method of "myobj"?  Then "self" is the
myobj instance.  It will acquire the attributes of its container
if it inherits from Acquisition.Implicit, which if it subclasses
Folder, it does.

That means you can refer to the "other" instance as:

self.other

or

getattr(self, 'other')

You don't need to use the explicit acquisition methods unless you
want to do something fancier like unwrap/re-wrap the instance
with a new acquisition wrapper or something (and it seems unlikely
that you need to).

(This is in product code -- i.e. you can use this within a method
of your MyFolder class).

I'm a little unclear on why you need to pass another instance to
your method (especially if it is the same instance so that

self is someinstance

is true).

Anyway, I *think* this answers your question, unless there's a
subtlety here that I'm missing.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Zope mailing list