[Zope] Test whether ZClass lines type property is empty
complaw@hal-pc.org
complaw@hal-pc.org
Thu, 4 Oct 2001 19:08:14 GMT
I've had this problem too.
Instead of checking for length, I check to see if the first
item on the list is <> ''. If there is nothing in the first
item, then I assume that it is an empty list. For the most
part, the assumption is valid.
for x in my_list:
if x <> '':
# do something...
Hope that helps,
Ron
> ZClass "lines" type property is a "list" in Python.
>
> If there are no values, it should render IMHO as an empty list in
> Python: []
>
> But it renders as a list containing single item. Something like: [""]
>
> Consequently, len(variable) is 1, whether there is one line or no lines.
>
> I cannot use <dtml-if "_.len(variable)>0"> to see if there are values.
>
> How can I discover if the list is empty without computationally
> expensive constructs?
>
> --
> Milos Prudek
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>