Re: [Zope] Test whether ZClass lines type property is empty
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 )
complaw@hal-pc.org wrote:
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.
Yeah, I do that, too. In a February 2001 message Dieter Maurer said that this behaviour is an "implementation artefact". IMHO there are either features or bugs. Is this a feature or a bug? IMHO it is an API bug. -- Milos Prudek
participants (2)
-
complaw@hal-pc.org -
Milos Prudek