John Schinnerer wrote:
> Aloha,
> 
> I have a python script, getCatalogItems(), which returns a (possibly
> empty) list resulting from a catalog query. The lone parameter is the
> sort index; the rest of the query is taken from the request. Anyhow...
> If nothing was found, I don't want to display an empty table of results.
> 
> When I do this query and then check for empty list to see if the query
> returned any items:
> 
> <div tal:define="items python:container.getCatalogItems('id')">
> <table tal:condition="python: items!=[]">
> ...
> 
> ...it doesn not work, that is, the (empty) table displays when items is
> in fact an empty list.
> 
> If I do this instead:
> 
> <div tal:define="items python:container.getCatalogItems('id')">
> <table tal:condition="python: len(items)>0">
> ...
> 
> ...then the condition works, no empty table is displayed if the list is
> empty.
> 
> Why does the former not work and the latter does?
> I need to understand the difference in the python expressions...makes no
> sense to me at present that they don't work the same.
> 
Well, thats because getCatalogItens() does not return a list. It might
look and work like it, but it isnt the same class. Python defines
comparisions between different classes as always false.

Easier in your case would be just:

tal:condition="items"

non empty python objects are usually logically True.

Regards
Tino
_______________________________________________
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 )

Reply via email to