title: Class generator without the __iter__() method but object instance works with next()
body: <p>I am trying to understand code that has a class to create a generator which is later iterated through with the next() built in fiction.</p>
  
  <p>The class in question is this:</p>
  
  <pre><code>Class MyGen():
      def __init__(self):
      """ Define some instance attributes"""
          self.foo = 'bar'
          self.some_attribute = 0
      def __next__(self):
          if self.some_attribute &lt; some_condition:
              new_value = self.argument1
              self.some_attribute += 1
              return new_value
  </code></pre>
  
  <p>In a global function, the returned object gets iterated through by the next() built in function. That is...</p>
  
  <pre><code>gen = Mygen()
  next(gen) # Returns values
  </code></pre>
  
  <p>I don't understand how the class can be a generator without the <code>__iter__()</code> method. Is the
   <code>__iter__()</code> method necessary to produce a generator from a class? Everywhere I search it seems that <code>__iter__()</code> and <code>__next__()</code> are used together to create a generator from a class.</p>
  
  <p>I'm fairly new to Python. This code sample was my best attempt at showing where the problem for me is, as the actual code does a lot more and would detract from the question and be too long to put here. I'm not experience enough to know how to shorten it more than this or more info is required.</p>