[Zope] PYTHON: Searching for an object inside a folder
Vitor Varalonga
vpedrosa@ciberbit.pt
Wed, 16 Oct 2002 16:33:20 +0100
--------------FACF010A01DC811ABD166FE8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
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?
kind regards,
Vitor Varalonga
--------------FACF010A01DC811ABD166FE8
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt> Hi!</tt>
<br><tt> </tt><tt></tt>
<p><tt> I need to check, inside a Python script,
if an object with a</tt>
<br><tt>particular ID exists inside a folder.</tt>
<br><tt> Right now I'm using the following code:</tt><tt></tt>
<p><tt> # this is the folder I want to search</tt>
<br><tt> myFolder = container.REQUEST.PARENTS[0].img_folder</tt><tt></tt>
<p><tt> # search the folder for an object with ID <object_id></tt>
<br><tt> obj = getattr(myFolder, object_id, None)</tt>
<br><tt> if obj is not None:</tt>
<br><tt> # there is no such object</tt>
<br><tt> else:</tt>
<br><tt> # there is an object
with that id</tt>
<br><tt> </tt><tt></tt>
<p><tt> Is there a more efficient way to perform this
operation?</tt>
<br><tt> </tt><tt></tt>
<p><tt>kind regards,</tt><tt></tt>
<p><tt>Vitor Varalonga</tt></html>
--------------FACF010A01DC811ABD166FE8--