[Zope] how do I test for the current item in an iteration

Dieter Maurer dieter at handshake.de
Fri Sep 28 14:18:45 EDT 2007


kamal hamzat wrote at 2007-9-28 16:36 +0100:
>I have this error after i added the if statement
>
>Error Type: TypeError
>Error Value: mybrains.__cmp__(x,y) requires y to be a 'mybrains', not a 'int'
>
>
>for i in context.zCatNewsCurrent():
>     if i <= 5:  
>        print "%s: %s: %s" % (i.id, i.author, i.summary)

You are aware that you use "i" both as an integer ("i <= 5")
as well as a structure ("i.id", "i.author", ...).

Python is quite polymorph -- but there are some limits.

Andreas suggestion was good: "enumerate" may help you...



-- 
Dieter


More information about the Zope mailing list