Jeff Schwab wrote:
> Robert Kern wrote:
>> Now, if I were to do
>>
>>   item = g(self, test).next()
>>
>> the generator would execute the code until it reached the yield 
>> statement which happens when it finds the first item that passes the 
>> test. That item will get returned, and execution does not return to 
>> the generator again.
[snip]
> Wow, that's cool!  Very reminiscent of C++ input iterators, but a lot 
> cleaner and shorter.  Thanks.

Read up on the __iter__ and __next__ methods that can be implemented by 
objects; Python objects have a very nice way of becoming (and returning) 
iterators.  Generator functions and expressions are magic ways of doing 
some Really Common Things as iterators.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to