[Zope] Re: PYTHON: Searching for an object inside a folder
Maik Jablonski
maik.jablonski@uni-bielefeld.de
Thu, 17 Oct 2002 00:30:28 +0200
Vitor Varalonga wrote:
> Hi!
>
>
> I need to check, inside a Python script, if an object with a
> particular ID exists inside a folder.
> Right now I'm using the following code:
>
> # this is the folder I want to search
> myFolder = container.REQUEST.PARENTS[0].img_folder
>
> # search the folder for an object with ID <object_id>
> obj = getattr(myFolder, object_id, None)
> if obj is not None:
> # there is no such object
> else:
> # there is an object with that id
>
>
> Is there a more efficient way to perform this operation?
hi,
untested..;-), but should work:
if hasattr(myFolder.aq_explicit,object_id):
# there is an object with object_id
else:
there is no object with object_id
myFolder.aq_explicit prevents aquiring from above...;-)
cheers, maik
--
Maik Jablonski __o
www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group
Bielefeld, Germany (_)/(_) www.dzug.org