Status of PEP's?

Emile van Sebille emile at fenx.com
Thu Feb 28 16:51:35 CET 2002


"Remco Gerlich"
> Compare:
>
> for i in 6: print i
> for i in 6,7: print i
> for i in 6,7,8: print i
>
> You wouldn't think the first line does something different, would you?

Is that really any different from what we have now:

for i in "Spam": print i
for i in "Spam","and": print i
for i in "Spam","and", "Eggs": print i

I find the best argument for adding an iter method to ints is that it
allows me to say:

    for ii in iter(len(mylist)):

which I find _much_ less confusing than saying:

    for ii in range(len(mylist)).

The first reads as:

    'for ii iterating over the len of mylist'

whereas the second:

    'for ii in the list of numbers starting with 0 to 1 less than the
len of mylist'


Of course,  this can be done now by simply(!!?) shadowing iter with:
iter = range.

If this PEP is added, the coincidental effect of ints invoking their
iterators in appropriate contexts is, in my mind, no different than what
we do today with strings.

However, the clarity and intent conveyed by allowing this, particularly
for newbies, more than offsets the gotcha's, which, once learned, is the
same set of gotcha's in place for strings.

Learn-each-idiom-only-once-ly y'rs

--

Emile van Sebille
emile at fenx.com

---------






More information about the Python-list mailing list