Aloha,

Thanks, I understand...though it's a bit annoying that it looks and acts just like a list but "isn't"...

Just using "items" does work. I figured it would work for True when not empty...I wasn't so sure what it would return when empty, as sometimes the test seems to be on 'exists' rather than 'empty', depending on the type of object.

At least I grok this particular case now, thanks again...
cheers,
John S.

Tino Wildenhain wrote:
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 )


--

John Schinnerer - MA, Whole Systems Design
------------------------------------------
- Eco-Living -
Whole Systems Design Services
People - Place - Learning - Integration
[EMAIL PROTECTED]
http://eco-living.net
_______________________________________________
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