[Tutor] 2.7.3 generator objects

Alan Gauld alan.gauld at btinternet.com
Sun Sep 2 08:39:28 CEST 2012

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(<path>)), that variable becomes a
> generator object that does not work in a for loop.

It does for me....

 >>> home = os.walk('/home/alang/src/Python')
 >>> for root,dirs,files in home:
...     print root

What happened when you tried?

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list