PEP 276 Simple Iterator for ints (fwd)
James_Althoff at i2.com
James_Althoff at i2.com
Wed Nov 28 18:45:10 EST 2001
Jeff Shannon wrote:
>Um, maybe I've missed something, but what does this have to do with
iterators?
>An iterator will never return results to a constant (thus, your "3 in 5"
example
>is still a syntax error). PEP 276 does not make an integer equivalent to
the
>list of natural numbers ending below it; it simply provides a way to
*iterate*
>over those numbers, in the context of a for-loop. "if x in 5" would still
be an
>invalid construct, even after "for x in 5" became legal. (Unless I'm
*severely*
>misunderstanding the intent...)
You are right in saying that PEP 276 calls for adding an iterator. If
types.IntType has an iterator then places in Python that are
"iterator-based" just work automatically without need for any further
changes. So, for example:
for rowindex in table.rowcount:
works because for-loops are (2.1 and after) iterator-based. No changes are
necessary in for-loops for this to happen.
And, if I'm not mistaken,
if index not in len(mylist):
also works because "in" is iterator-based (in 2.1 or 2.2). No changes are
necessary to "if" statements for this to work (assuming again that "in" has
become iterator-based).
Jim
More information about the Python-list
mailing list