[Zope3-Users] Using 'if object' evaluates false even if
objectexists
Giovannetti, Mark
giovanne at nrcan.gc.ca
Thu Apr 12 16:58:02 EDT 2007
Hi Aleksander,
Thanks for your response. And thanks to Benji, too, for
replying with the informative link. More below...
> From zope3-users On Behalf Of Aleksander Kowalczyk
>
> 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.
>
This occurred to me at about the same time I read your message.
The context is indeed a container (which happened to be empty),
thus the false evaluation as you suggest.
Another nugget of useful python/zope programming knowledge!
Regards
Mark
More information about the Zope3-users
mailing list