RE: [Zope] Simple Comparison - How to find the Template you are in in a list of all files in a directory
[ Edward Pollard]
I've been attempting to iterate through the list and then compare the file ID of the item in the repeat loop with the file ID of the template using 'cmp'. I cannot get cmp to return 0 even when the names are the same (as evaluated by displaying them in the template).
Is this the incorrect way to compare strings? Is there a better way to do this?
if a==b: #do something Cheers, Tom P
On Thursday, September 12, 2002, at 11:39 AM, Passin,Thomas B. (Tom) wrote:
[ Edward Pollard]
I've been attempting to iterate through the list and then compare the file ID of the item in the repeat loop with the file ID of the template using 'cmp'. I cannot get cmp to return 0 even when the names are the same (as evaluated by displaying them in the template).
Is this the incorrect way to compare strings? Is there a better way to do this?
if a==b: #do something
I tried this. It did not work. My thoughts are that == would compare the pointers to the objects, not the contents. Code wise, I have this <span tal:condition="python:items.title_or_id == template.title_or_id" tal:replace="Content I want">Filler</span> items being the list I'm iterating through. So the obvious (==) didn't work (apologies for not clarifying this in the first place), the next-obvious (cmp) didn't work, what will? Edward
Hi Edward, [...]
I tried this. It did not work. My thoughts are that == would compare the pointers to the objects, not the contents.
Code wise, I have this <span tal:condition="python:items.title_or_id == template.title_or_id" tal:replace="Content I want">Filler</span> [...]
Ever tried <span tal:content="python:items.title_or_id" /> for You can see what You are comparing? :) Unlike path notation, python notation does no call the objects implicitely; thus You compare method objects of different Zope objects; they are different. Try: <span tal:condition="python:items.title_or_id() == template.title_or_id()" tal:replace="Content I want">Filler</span> Cheers, Clemens P.S.: as You want to compare the objects You could compare quite as well: <span tal:condition="python:items.getId() == template.getId()" tal:replace="Content I want">Filler</span> or even <span tal:condition="python:items == template" tal:replace="Content I want">Filler</span>
participants (3)
-
Clemens Klein-Robbenhaar -
Edward Pollard -
Passin,Thomas B. (Tom)