title: Python custom iterator: iteration over non-sequence
body: <p>I'm trying to create an iterator that extracts every word from a text file and iterates through them. This is what I have right now:</p>
  
  <pre><code>class String_iterator:
      def __init__(self, filename):
          self.words = []
          f = open(filename, 'r')
          lines = f.readlines()
          for line in lines:
              self.words.extend(line.split(" "))
          self.ind = 0
          self.size = len(self.words)
  
      def __iter_(self):
          return self
  
      def next(self):
          if self.ind &gt; self.size:
              raise StopIteration
          else:
              self.ind += 1
              return self.words[self.ind-1]
  </code></pre>
  
  <p>Comparing it to functional simple examples of Python iterators, I can't figure out why it isn't working when I try to use it in even a simple case:</p>
  
  <pre><code>sit = String_iterator(filename)
  for word in sit:
      print word
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "WordCounter.py", line 68, in &lt;module&gt;
      for word in sit:
  TypeError: iteration over non-sequence
  </code></pre>
  
  <p>I am guessing that there is something wrong with the <code>String_iterator</code> that it's not a proper iterator, but I can't figure out what.</p>
  
  <p>(I'm also having issues with the encoding on reading in the file, but that's another issue altogether...)</p>