[Zope3-Users] Using 'if object' evaluates false even if object exists

Aleksander Kowalczyk thealx at poczta.onet.pl
Thu Apr 12 16:39:49 EDT 2007


On 4/12/07, Giovannetti, Mark <giovanne at nrcan.gc.ca> wrote:
>
> Hi list,
>
> Hope everyone's having a splendid day/evening/whatever.
>
> I've encountered a strange error.  I have two chunks
> of nearly identical code below.  The only difference
> is the first "if" statement.  One has:
>
>     if context:
>
> the other has:
>
>     if context is not None
>
> The first fails to be true even if context is not None.
> This can be seen by the output from the logs showing the
> context variable as:
>

Possibly a context is a container-like object.
For containers operation
"if context" is equal to "if len(context) > 0".  So even if context is not
None, it still may be False if the container does not contain any elements.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20070412/b1599d10/attachment.htm


More information about the Zope3-users mailing list