Status of PEP's?

Andy Gimblett gimbo at ftech.net
Thu Feb 28 11:41:44 EST 2002


On Thu, Feb 28, 2002 at 07:51:35AM -0800, Emile van Sebille wrote:
> 
> > 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

Yes, it really is.  "Spam" is a sequence, whereas 6 isn't.

> 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'

I find the second much more explicit and much less ambiguous, and
therefore far preferable.

To me, "the len of mylist" is the number of items in the list - a
single value, not some other list.  If I don't happen to know what
range() does because I'm a newbie, it's easy to find out and get a
clear, unambiguous, unsurprising answer.

> 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.

I disagree - strings are sequences, integers aren't.

-Andy

-- 
Andy Gimblett - Programmer - Frontier Internet Services Limited
Tel: 029 20 820 044 Fax: 029 20 820 035 http://www.frontier.net.uk/
Statements made are at all times subject to Frontier's Terms and
Conditions of Business, which are available upon request.




More information about the Python-list mailing list