Re: [Zope] if object does not exist in python
Garito wrote: Checks for named object inside the container that the script is in. hasattr(container, 'id') NO! This is bad for two reasons: 1. It'll acquire id from other places 2. It'll swallow any exceptions found in trying to get hold of 'id', inlcuding ConflictErrors, which is "bad" :-S cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] if object does not exist in python
- Original Message - From: "Andrew Milton" <[EMAIL PROTECTED]> To: "Garito" <[EMAIL PROTECTED]> Cc: "zope" Sent: Wednesday, December 13, 2006 9:40 AM Subject: Re: [Zope] if object does not exist in python +---[ Garito ]-- | Andrew Milton escribi?: | >+---[ David Bear ]-- | >| Can anyone show me code examples of a script that checks for the | >| existences of a named object? | > | >if namedObject in container.objectIds(): | > # object exists | >else: | > # doesn't | > | > | >Checks for named object inside the container that the script is in. | > | > | hasattr(container, 'id') That will acquire... And the ever popular: obj = context.restrictedTraverse('/path/to/object/objId', None) if obj is None: # object not found else: # object exists Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] if object does not exist in python
+---[ Garito ]-- | Andrew Milton escribi?: | >+---[ David Bear ]-- | >| Can anyone show me code examples of a script that checks for the | >| existences of a named object? | > | >if namedObject in container.objectIds(): | > # object exists | >else: | > # doesn't | > | > | >Checks for named object inside the container that the script is in. | > | > | hasattr(container, 'id') That will acquire... -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] if object does not exist in python
Andrew Milton escribió: +---[ David Bear ]-- | Can anyone show me code examples of a script that checks for the | existences of a named object? if namedObject in container.objectIds(): # object exists else: # doesn't Checks for named object inside the container that the script is in. hasattr(container, 'id') ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] if object does not exist in python
+---[ David Bear ]-- | Can anyone show me code examples of a script that checks for the | existences of a named object? if namedObject in container.objectIds(): # object exists else: # doesn't Checks for named object inside the container that the script is in. -- Andrew Milton [EMAIL PROTECTED] ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )