<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Iterators, Iterables, and Generators! Oh, my!</title>
	<atom:link href="http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/</link>
	<description>one man's journey into python...</description>
	<lastBuildDate>Fri, 03 Feb 2012 23:11:24 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Sumudu Fernando</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-238717</link>
		<dc:creator>Sumudu Fernando</dc:creator>
		<pubDate>Fri, 27 Jan 2012 09:43:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-238717</guid>
		<description>@spititan: Your example works, but the language does require iterators to implement __iter__.  What you have defined is almost an iterator, but technically isn&#039;t one.  The reason this requirement exists is that it makes it easy to write functions that can accept either an iterable or an iterator, the same way that built-ins such as sum can.

More precisely, if we write a loop like:

for x in iter(foo):
  pass

then foo can be either an iterable or an iterator.

One thing about the examples in the article is that they are slightly more complicated than necessary.  For example, I would write:

def forward(self):
  for c in self.data:
    yield ord(c)

and

def reverse(self):
  for c in reversed(self.data):
    yield ord(c)

(though maybe the reversed built-in did not exist when the article was written)</description>
		<content:encoded><![CDATA[<p>@spititan: Your example works, but the language does require iterators to implement __iter__.  What you have defined is almost an iterator, but technically isn&#8217;t one.  The reason this requirement exists is that it makes it easy to write functions that can accept either an iterable or an iterator, the same way that built-ins such as sum can.</p>
<p>More precisely, if we write a loop like:</p>
<p>for x in iter(foo):<br />
  pass</p>
<p>then foo can be either an iterable or an iterator.</p>
<p>One thing about the examples in the article is that they are slightly more complicated than necessary.  For example, I would write:</p>
<p>def forward(self):<br />
  for c in self.data:<br />
    yield ord(c)</p>
<p>and</p>
<p>def reverse(self):<br />
  for c in reversed(self.data):<br />
    yield ord(c)</p>
<p>(though maybe the reversed built-in did not exist when the article was written)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spititan</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-190761</link>
		<dc:creator>spititan</dc:creator>
		<pubDate>Fri, 22 Apr 2011 00:05:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-190761</guid>
		<description>This is a good article, but I just want to point out that a few things in this article is actually a bit misleading.

An iterator actually does not need to have an __iter__ method. next() is the only required method. The &#039;in&#039; operator of Python actually calls __iter__ method on an iterable, then call next() method on the returned iterator.

See the following example code

#!/usr/bin/python2.6

class ByteValue(object):
  def __init__(self, data):
    self.data = data

  class Iterator(object):
    def __init__(self, data):
      self.data = data
      self.index = 0

    def next(self):
      if self.index == len(self.data):
        raise StopIteration
      else:
        byte_value = ord(self.data[self.index])
        self.index += 1
        return byte_value

  def __iter__(self):
    return ByteValue.Iterator(self.data)


bv = ByteValue(&quot;abcdefg&quot;)
for byte_value in bv:
  print(byte_value)

for byte_value in bv:
  print(byte_value)


In this example, ByteValue is interable, the iterator for him is ByteValue.Iterator, which does not have __iter__ method.</description>
		<content:encoded><![CDATA[<p>This is a good article, but I just want to point out that a few things in this article is actually a bit misleading.</p>
<p>An iterator actually does not need to have an __iter__ method. next() is the only required method. The &#8216;in&#8217; operator of Python actually calls __iter__ method on an iterable, then call next() method on the returned iterator.</p>
<p>See the following example code</p>
<p>#!/usr/bin/python2.6</p>
<p>class ByteValue(object):<br />
  def __init__(self, data):<br />
    self.data = data</p>
<p>  class Iterator(object):<br />
    def __init__(self, data):<br />
      self.data = data<br />
      self.index = 0</p>
<p>    def next(self):<br />
      if self.index == len(self.data):<br />
        raise StopIteration<br />
      else:<br />
        byte_value = ord(self.data[self.index])<br />
        self.index += 1<br />
        return byte_value</p>
<p>  def __iter__(self):<br />
    return ByteValue.Iterator(self.data)</p>
<p>bv = ByteValue(&#8220;abcdefg&#8221;)<br />
for byte_value in bv:<br />
  print(byte_value)</p>
<p>for byte_value in bv:<br />
  print(byte_value)</p>
<p>In this example, ByteValue is interable, the iterator for him is ByteValue.Iterator, which does not have __iter__ method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Thiessen</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-178078</link>
		<dc:creator>Matt Thiessen</dc:creator>
		<pubDate>Fri, 17 Dec 2010 17:53:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-178078</guid>
		<description>A good explanation and examples of iterator of a class.  Helped me solve my issue.  Thanks</description>
		<content:encoded><![CDATA[<p>A good explanation and examples of iterator of a class.  Helped me solve my issue.  Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: selsine</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-161342</link>
		<dc:creator>selsine</dc:creator>
		<pubDate>Tue, 23 Feb 2010 21:10:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-161342</guid>
		<description>Hi Henry,

Thanks for the kind words. I&#039;m trying to resume blogging as best I can but a one moth old eats up a lot of free time! Not to mention moving cities and a new house!

I have something that I&#039;m hoping to get up soon, and hopefully in the future there will be less time between posts!

mark</description>
		<content:encoded><![CDATA[<p>Hi Henry,</p>
<p>Thanks for the kind words. I&#8217;m trying to resume blogging as best I can but a one moth old eats up a lot of free time! Not to mention moving cities and a new house!</p>
<p>I have something that I&#8217;m hoping to get up soon, and hopefully in the future there will be less time between posts!</p>
<p>mark</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henry Dominik</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-161276</link>
		<dc:creator>Henry Dominik</dc:creator>
		<pubDate>Tue, 23 Feb 2010 13:44:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-161276</guid>
		<description>He seems to have resumed blogging again. Check out the post he made in January of this year. I&#039;m happy he&#039;s back :)</description>
		<content:encoded><![CDATA[<p>He seems to have resumed blogging again. Check out the post he made in January of this year. I&#8217;m happy he&#8217;s back <img src='http://www.learningpython.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PC Repair</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-154080</link>
		<dc:creator>PC Repair</dc:creator>
		<pubDate>Sun, 29 Nov 2009 17:14:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-154080</guid>
		<description>Just wondering why we have not seen you in a long time. 
I personally have missed your amazing step-by-step tutorial.

We hope you&#039;re fine and wish you the very best.
Good luck</description>
		<content:encoded><![CDATA[<p>Just wondering why we have not seen you in a long time.<br />
I personally have missed your amazing step-by-step tutorial.</p>
<p>We hope you&#8217;re fine and wish you the very best.<br />
Good luck</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cillia johnson</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-154079</link>
		<dc:creator>Cillia johnson</dc:creator>
		<pubDate>Sun, 29 Nov 2009 17:11:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-154079</guid>
		<description>This is great. I was having difficulties because of spaces in my indentation, but that has now been solved. It took me days to figure the indentation problem out as a beginner :)

Nice tutorial BTW ..</description>
		<content:encoded><![CDATA[<p>This is great. I was having difficulties because of spaces in my indentation, but that has now been solved. It took me days to figure the indentation problem out as a beginner <img src='http://www.learningpython.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Nice tutorial BTW ..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SoftwareExplorer</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-153423</link>
		<dc:creator>SoftwareExplorer</dc:creator>
		<pubDate>Thu, 19 Nov 2009 23:19:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-153423</guid>
		<description>You said &quot;handled so *wall*&quot; instead of &quot;handled so *well*&quot;. Ted mentioned this, but he was talking about a few other errors two, so you probably didn&#039;t notice the change.

Thanks for these tutorials. They are the best I have found so far.</description>
		<content:encoded><![CDATA[<p>You said &#8220;handled so *wall*&#8221; instead of &#8220;handled so *well*&#8221;. Ted mentioned this, but he was talking about a few other errors two, so you probably didn&#8217;t notice the change.</p>
<p>Thanks for these tutorials. They are the best I have found so far.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ksamuel</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-151649</link>
		<dc:creator>ksamuel</dc:creator>
		<pubDate>Wed, 07 Oct 2009 10:29:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-151649</guid>
		<description>Makes me think of this tuto :

http://stackoverflow.com/questions/231767#answer-231855</description>
		<content:encoded><![CDATA[<p>Makes me think of this tuto :</p>
<p><a href="http://stackoverflow.com/questions/231767#answer-231855" rel="nofollow">http://stackoverflow.com/questions/231767#answer-231855</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rune</title>
		<link>http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/comment-page-1/#comment-148472</link>
		<dc:creator>Rune</dc:creator>
		<pubDate>Mon, 13 Jul 2009 12:06:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learningpython.com/?p=110#comment-148472</guid>
		<description>Very informative and well written article!</description>
		<content:encoded><![CDATA[<p>Very informative and well written article!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

