[Python-iterators] Re: PEP 234: Iterators
Just van Rossum
just at letterror.com
Tue May 1 16:35:38 EDT 2001
Thomas Bellman wrote:
>
> Just van Rossum <just at letterror.com> wrote:
>
> > I think it will be rare for iterators created "manually" with iter(obj) to
> > be passed "manually" to a for loop.
>
> And just to contradict you, my very first use of Python iterators
> did exactly that. Of course, my iterator had special methods
> set_start() and set_end() in order to make it start at a certain
> position in the sequence and end at another.
>
> My program was to download a set of web pages, indexed by a date
> in the URL. The next() method in the iterator generated the URL
> for the next day, and I didn't want it to start trying to download
> 2000 years worth of web pages... Thus I would do:
>
> ui = iter(obj)
> ui.set_start(2000,4,23)
> ui.set_end(2000,5,29)
> for url in ui:
> urlopen.urlretrieve(url)
>
> to download the pages pertaining to dates between April 23rd and
> May 29th, inclusive, last year. (Actually, it is a bit more
> complicated than that, but at least that is the gist of it.)
Good show! Very nice example: I couldn't dream up a good alternative
spelling that doesn't prove me wrong ;-)
Just
More information about the Python-list
mailing list