TALES Iterator
There are no attributes in this class.
Letter()
Get the iterator position as an upper-case letter
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.Letter() 'A' >>> it.next() True >>> it.Letter() 'B' >>> it.next() True >>> it.Letter() 'C'
Roman(rnvalues=((1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')))
Get the iterator position as an upper-case roman numeral
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.Roman() 'I' >>> it.next() True >>> it.Roman() 'II' >>> it.next() True >>> it.Roman() 'III'
end()
Test whether the position is the last position
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.end() False >>> it.next() True >>> it.end() False >>> it.next() True >>> it.end() True
>>> it = Iterator('foo', {}, context) >>> it.end() False >>> it.next() False >>> it.end() False
even()
Test whether the position is even
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.even() True >>> it.next() True >>> it.even() False >>> it.next() True >>> it.even() True
index()
Get the iterator index
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> int(bool(it.next())) 1 >>> it.index() 0 >>> int(bool(it.next())) 1 >>> it.index() 1 >>> int(bool(it.next())) 1 >>> it.index() 2
item()
Get the iterator value
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.item() 'apple' >>> it.next() True >>> it.item() 'pear' >>> it.next() True >>> it.item() 'orange'
>>> it = Iterator('foo', {1:2}, context) >>> it.next() True >>> it.item() 1
length()
Get the length of the iterator sequence
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.length() 3
You can even get the length of a mapping:
>>> it = Iterator('foo', {"apple":1, "pear":2, "orange":3}, context) >>> it.length() 3
But you can't get the length of an iterable which doesn't support len():
>>> class MyIter(object): ... def __init__(self, seq): ... self._next = iter(seq).next ... def __iter__(self): ... return self ... def next(self): ... return self._next() >>> it = Iterator('foo', MyIter({"apple":1, "pear":2}), context) >>> it.length() Traceback (most recent call last): ... TypeError: len() of unsized object
letter(base=97, radix=26)
Get the iterator position as a lower-case letter
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.letter() 'a' >>> it.next() True >>> it.letter() 'b' >>> it.next() True >>> it.letter() 'c'
next()
Advance the iterator, if possible.
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> bool(it.next()) True >>> context.vars['foo'] 'apple' >>> bool(it.next()) True >>> context.vars['foo'] 'pear' >>> bool(it.next()) True >>> context.vars['foo'] 'orange' >>> bool(it.next()) False
>>> it = Iterator('foo', {"apple":1, "pear":1, "orange":1}, context) >>> bool(it.next()) True >>> bool(it.next()) True >>> bool(it.next()) True >>> bool(it.next()) False
>>> it = Iterator('foo', (), context) >>> bool(it.next()) False
>>> it = Iterator('foo', {}, context) >>> bool(it.next()) False
If we can advance, set a local variable to the new value.
number()
Get the iterator position
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> int(bool(it.next())) 1 >>> it.number() 1 >>> int(bool(it.next())) 1 >>> it.number() 2 >>> int(bool(it.next())) 1 >>> it.number() 3
odd()
Test whether the position is odd
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.odd() False >>> it.next() True >>> it.odd() True >>> it.next() True >>> it.odd() False
parity()
Return 'odd' or 'even' depending on the position's parity
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.parity() 'odd' >>> it.next() True >>> it.parity() 'even' >>> it.next() True >>> it.parity() 'odd'
roman()
Get the iterator position as a lower-case roman numeral
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.roman() 'i' >>> it.next() True >>> it.roman() 'ii' >>> it.next() True >>> it.roman() 'iii'
start()
Test whether the position is the first position
>>> context = Context(ExpressionEngine(), {}) >>> it = Iterator('foo', ("apple", "pear", "orange"), context) >>> it.next() True >>> it.start() True >>> it.next() True >>> it.start() False >>> it.next() True >>> it.start() False
>>> it = Iterator('foo', {}, context) >>> it.start() False >>> it.next() False >>> it.start() False
There are no known subclasses.