Re: [Tutor] a question about iterators

2008-06-17 Thread Kent Johnson
On Tue, Jun 17, 2008 at 1:46 AM, Christopher Spears <[EMAIL PROTECTED]> wrote: > I am confused by this statement: i = iter(a) > > Why do I need to turn 'a' into an iterator? Didn't I already do this when I > constructed the class? Yes, a is already an iterator. > As a test, I tried the fo

[Tutor] a question about iterators

2008-06-16 Thread Christopher Spears
I've been learning about how to implement an iterator in a class from Core Python Programming (2nd Edition). >>> class AnyIter(object): ... def __init__(self, data, safe=False): ... self.safe = safe ... self.iter = iter(data) ... ... def __iter__(self): ... return self