Other Objects

class zope.tales.tales.Iterator(name, seq, context)[source]

TALES Iterator.

Default implementation of zope.tales.interfaces.ITALESIterator.

Construct an iterator

Iterators are defined for a name, a sequence, or an iterator and a context, where a context simply has a setLocal method:

>>> context = Context(ExpressionEngine(), {})
>>> it = Iterator('foo', ("apple", "pear", "orange"), context)

A local variable is not set until the iterator is used:

>>> int("foo" in context.vars)
0

We can create an iterator on an empty sequence:

>>> it = Iterator('foo', (), context)

An iterator works as well:

>>> it = Iterator('foo', {"apple":1, "pear":1, "orange":1}, context)
>>> next(it)
True
>>> it = Iterator('foo', {}, context)
>>> next(it)
False
>>> it = Iterator('foo', iter((1, 2, 3)), context)
>>> next(it)
True
>>> next(it)
True