Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread Peter Otten
Steven D'Aprano wrote: > On 02/09/12 17:09, Ray Jones wrote: > >> But didn't I read somewhere that you can reset an iterator to go through >> the whole process again? > > In general, no. > > The usual way to "reset" an iterator is to re-create it. > > > walker = os.walk("/home/steve/start") >

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread Steven D'Aprano
On 02/09/12 17:09, Ray Jones wrote: But didn't I read somewhere that you can reset an iterator to go through the whole process again? In general, no. The usual way to "reset" an iterator is to re-create it. walker = os.walk("/home/steve/start") # ... process files in walker walker = os.walk

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 3:09 AM, Ray Jones wrote: > > But didn't I read somewhere that you can reset an iterator to go through > the whole process again? You could implement that ability in your own objects, but it's not part of the protocol. I forgot to mention generator expressions. This is an

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread Ray Jones
On 09/01/2012 11:57 PM, eryksun wrote: > To be an iterable in general, it suffices to have either an __iter__ > method or a __getitem__ method. Here are the glossary definitions: > http://docs.python.org/glossary.html#term-iterable > http://docs.python.org/glossary.html#term-iterator After a few

Re: [Tutor] 2.7.3 generator objects

2012-09-02 Thread eryksun
On Sun, Sep 2, 2012 at 1:44 AM, Ray Jones wrote: > > I was playing with os.walk today. I can use os.walk in a for loop (does > that make it an iterator or just an irritable? ^_^), The output from os.walk is a generator, which is an iterator. os.walk actually calls itself recursively, creating a c

Re: [Tutor] 2.7.3 generator objects

2012-09-01 Thread Ray Jones
On 09/01/2012 11:39 PM, Alan Gauld wrote: > On 02/09/12 06:44, Ray Jones wrote: >> I was playing with os.walk today. I can use os.walk in a for loop (does >> that make it an iterator or just an irritable? ^_^), but if I assign >> os.walk to 'test' (test = os.walk()), that variable becomes a >> gen

Re: [Tutor] 2.7.3 generator objects

2012-09-01 Thread Alan Gauld
On 02/09/12 06:44, Ray Jones wrote: I was playing with os.walk today. I can use os.walk in a for loop (does that make it an iterator or just an irritable? ^_^), but if I assign os.walk to 'test' (test = os.walk()), that variable becomes a generator object that does not work in a for loop. It d