Status of PEP's?

Delaney, Timothy tdelaney at avaya.com
Thu Feb 28 18:21:36 EST 2002


> I'd also like to put in my (unrequested) two cents and go on record as
> disliking the "for i in 5" syntax. Not just as a matter of taste, but
> because it provides unintuitive behavior, as pointed out previously.
> The two lines...
>     for i in 5: print i
>     for i in 5, 6: print i
> ...would behave differently under the proposal.

They behave differently now. One is a syntax error, the other isn't.

For the record (I've said this before), I like the idea of integers being
iterable (and I'm not a set theory wonk). I never think of it though as

for i in 5:
    print i

but always as

for i in len(seq):
    print i

or something similar, which has obvious semantic logic. However, I could see
myself happily using for i in 5: in a quick script.

One important thing to remember, which I think a few people have missed, is
that an integer will not be an iterator. An integer will be iterable - that
is, to get this behaviour, iter(integer) must be called at some stage. This
is done transparently in a for: loop. Are the following two equivalent
though?

if 1 in obj:
    pass

if 1 in iter(obj):
    pass

i.e. is iter(obj) called implicitly in the first case?

Tim Delaney




More information about the Python-list mailing list